aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitmodules3
-rw-r--r--ext/bg/data/options-schema.json8
-rw-r--r--ext/bg/js/backend.js114
-rw-r--r--ext/bg/js/japanese.js40
-rw-r--r--ext/bg/js/options.js3
-rw-r--r--ext/bg/js/search.js2
-rw-r--r--ext/bg/js/settings/main.js2
-rw-r--r--ext/bg/js/translator.js17
-rw-r--r--ext/bg/settings.html11
-rw-r--r--ext/fg/js/float.js6
-rw-r--r--ext/fg/js/frame-offset-forwarder.js4
-rw-r--r--ext/fg/js/frontend-initialize.js4
-rw-r--r--ext/fg/js/frontend.js8
-rw-r--r--ext/mixed/css/display.css24
-rw-r--r--ext/mixed/display-templates.html4
-rw-r--r--ext/mixed/js/api.js4
-rw-r--r--ext/mixed/js/display-generator.js237
-rw-r--r--ext/mixed/js/display.js4
-rw-r--r--ext/mixed/js/text-scanner.js2
-rw-r--r--package-lock.json44
-rw-r--r--package.json2
-rw-r--r--test/test-japanese.js54
22 files changed, 369 insertions, 228 deletions
diff --git a/.gitmodules b/.gitmodules
deleted file mode 100644
index 1d7e60d4..00000000
--- a/.gitmodules
+++ /dev/null
@@ -1,3 +0,0 @@
-[submodule "ext/bg/lang/data"]
- path = ext/bg/lang/data
- url = https://FooSoft@bitbucket.org/FooSoft/yomichan-data.git
diff --git a/ext/bg/data/options-schema.json b/ext/bg/data/options-schema.json
index da1f1ce0..4f9e694d 100644
--- a/ext/bg/data/options-schema.json
+++ b/ext/bg/data/options-schema.json
@@ -388,7 +388,8 @@
"convertNumericCharacters",
"convertAlphabeticCharacters",
"convertHiraganaToKatakana",
- "convertKatakanaToHiragana"
+ "convertKatakanaToHiragana",
+ "collapseEmphaticSequences"
],
"properties": {
"convertHalfWidthCharacters": {
@@ -415,6 +416,11 @@
"type": "string",
"enum": ["false", "true", "variant"],
"default": "variant"
+ },
+ "collapseEmphaticSequences": {
+ "type": "string",
+ "enum": ["false", "true", "full"],
+ "default": "false"
}
}
},
diff --git a/ext/bg/js/backend.js b/ext/bg/js/backend.js
index 4a36be57..eb1f3e7b 100644
--- a/ext/bg/js/backend.js
+++ b/ext/bg/js/backend.js
@@ -75,33 +75,33 @@ class Backend {
this.messageToken = yomichan.generateId(16);
this._messageHandlers = new Map([
- ['yomichanCoreReady', this._onApiYomichanCoreReady.bind(this)],
- ['optionsSchemaGet', this._onApiOptionsSchemaGet.bind(this)],
- ['optionsGet', this._onApiOptionsGet.bind(this)],
- ['optionsGetFull', this._onApiOptionsGetFull.bind(this)],
- ['optionsSet', this._onApiOptionsSet.bind(this)],
- ['optionsSave', this._onApiOptionsSave.bind(this)],
- ['kanjiFind', this._onApiKanjiFind.bind(this)],
- ['termsFind', this._onApiTermsFind.bind(this)],
- ['textParse', this._onApiTextParse.bind(this)],
- ['textParseMecab', this._onApiTextParseMecab.bind(this)],
- ['definitionAdd', this._onApiDefinitionAdd.bind(this)],
- ['definitionsAddable', this._onApiDefinitionsAddable.bind(this)],
- ['noteView', this._onApiNoteView.bind(this)],
- ['templateRender', this._onApiTemplateRender.bind(this)],
- ['commandExec', this._onApiCommandExec.bind(this)],
- ['audioGetUri', this._onApiAudioGetUri.bind(this)],
- ['screenshotGet', this._onApiScreenshotGet.bind(this)],
- ['forward', this._onApiForward.bind(this)],
- ['frameInformationGet', this._onApiFrameInformationGet.bind(this)],
- ['injectStylesheet', this._onApiInjectStylesheet.bind(this)],
- ['getEnvironmentInfo', this._onApiGetEnvironmentInfo.bind(this)],
- ['clipboardGet', this._onApiClipboardGet.bind(this)],
- ['getDisplayTemplatesHtml', this._onApiGetDisplayTemplatesHtml.bind(this)],
- ['getQueryParserTemplatesHtml', this._onApiGetQueryParserTemplatesHtml.bind(this)],
- ['getZoom', this._onApiGetZoom.bind(this)],
- ['getMessageToken', this._onApiGetMessageToken.bind(this)],
- ['getDefaultAnkiFieldTemplates', this._onApiGetDefaultAnkiFieldTemplates.bind(this)]
+ ['yomichanCoreReady', {handler: this._onApiYomichanCoreReady.bind(this), async: false}],
+ ['optionsSchemaGet', {handler: this._onApiOptionsSchemaGet.bind(this), async: false}],
+ ['optionsGet', {handler: this._onApiOptionsGet.bind(this), async: false}],
+ ['optionsGetFull', {handler: this._onApiOptionsGetFull.bind(this), async: false}],
+ ['optionsSet', {handler: this._onApiOptionsSet.bind(this), async: true}],
+ ['optionsSave', {handler: this._onApiOptionsSave.bind(this), async: true}],
+ ['kanjiFind', {handler: this._onApiKanjiFind.bind(this), async: true}],
+ ['termsFind', {handler: this._onApiTermsFind.bind(this), async: true}],
+ ['textParse', {handler: this._onApiTextParse.bind(this), async: true}],
+ ['textParseMecab', {handler: this._onApiTextParseMecab.bind(this), async: true}],
+ ['definitionAdd', {handler: this._onApiDefinitionAdd.bind(this), async: true}],
+ ['definitionsAddable', {handler: this._onApiDefinitionsAddable.bind(this), async: true}],
+ ['noteView', {handler: this._onApiNoteView.bind(this), async: true}],
+ ['templateRender', {handler: this._onApiTemplateRender.bind(this), async: true}],
+ ['commandExec', {handler: this._onApiCommandExec.bind(this), async: false}],
+ ['audioGetUri', {handler: this._onApiAudioGetUri.bind(this), async: true}],
+ ['screenshotGet', {handler: this._onApiScreenshotGet.bind(this), async: true}],
+ ['broadcastTab', {handler: this._onApiBroadcastTab.bind(this), async: false}],
+ ['frameInformationGet', {handler: this._onApiFrameInformationGet.bind(this), async: true}],
+ ['injectStylesheet', {handler: this._onApiInjectStylesheet.bind(this), async: true}],
+ ['getEnvironmentInfo', {handler: this._onApiGetEnvironmentInfo.bind(this), async: true}],
+ ['clipboardGet', {handler: this._onApiClipboardGet.bind(this), async: true}],
+ ['getDisplayTemplatesHtml', {handler: this._onApiGetDisplayTemplatesHtml.bind(this), async: true}],
+ ['getQueryParserTemplatesHtml', {handler: this._onApiGetQueryParserTemplatesHtml.bind(this), async: true}],
+ ['getZoom', {handler: this._onApiGetZoom.bind(this), async: true}],
+ ['getMessageToken', {handler: this._onApiGetMessageToken.bind(this), async: false}],
+ ['getDefaultAnkiFieldTemplates', {handler: this._onApiGetDefaultAnkiFieldTemplates.bind(this), async: false}]
]);
this._commandHandlers = new Map([
@@ -165,16 +165,23 @@ class Backend {
}
onMessage({action, params}, sender, callback) {
- const handler = this._messageHandlers.get(action);
- if (typeof handler !== 'function') { return false; }
+ const messageHandler = this._messageHandlers.get(action);
+ if (typeof messageHandler === 'undefined') { return false; }
+
+ const {handler, async} = messageHandler;
try {
- const promise = handler(params, sender);
- promise.then(
- (result) => callback({result}),
- (error) => callback({error: errorToJson(error)})
- );
- return true;
+ const promiseOrResult = handler(params, sender);
+ if (async) {
+ promiseOrResult.then(
+ (result) => callback({result}),
+ (error) => callback({error: errorToJson(error)})
+ );
+ return true;
+ } else {
+ callback({result: promiseOrResult});
+ return false;
+ }
} catch (error) {
callback({error: errorToJson(error)});
return false;
@@ -311,27 +318,26 @@ class Backend {
_onApiYomichanCoreReady(_params, sender) {
// tab ID isn't set in background (e.g. browser_action)
+ const callback = () => this.checkLastError(chrome.runtime.lastError);
+ const data = {action: 'backendPrepared'};
if (typeof sender.tab === 'undefined') {
- const callback = () => this.checkLastError(chrome.runtime.lastError);
- chrome.runtime.sendMessage({action: 'backendPrepared'}, callback);
- return Promise.resolve();
+ chrome.runtime.sendMessage(data, callback);
+ return false;
+ } else {
+ chrome.tabs.sendMessage(sender.tab.id, data, callback);
+ return true;
}
-
- const tabId = sender.tab.id;
- return new Promise((resolve) => {
- chrome.tabs.sendMessage(tabId, {action: 'backendPrepared'}, resolve);
- });
}
- async _onApiOptionsSchemaGet() {
+ _onApiOptionsSchemaGet() {
return this.getOptionsSchema();
}
- async _onApiOptionsGet({optionsContext}) {
+ _onApiOptionsGet({optionsContext}) {
return this.getOptions(optionsContext);
}
- async _onApiOptionsGetFull() {
+ _onApiOptionsGetFull() {
return this.getFullOptions();
}
@@ -538,7 +544,7 @@ class Backend {
return this._renderTemplate(template, data);
}
- async _onApiCommandExec({command, params}) {
+ _onApiCommandExec({command, params}) {
return this._runCommand(command, params);
}
@@ -558,15 +564,15 @@ class Backend {
});
}
- _onApiForward({action, params}, sender) {
+ _onApiBroadcastTab({action, params}, sender) {
if (!(sender && sender.tab)) {
- return Promise.resolve();
+ return false;
}
const tabId = sender.tab.id;
- return new Promise((resolve) => {
- chrome.tabs.sendMessage(tabId, {action, params}, (response) => resolve(response));
- });
+ const callback = () => this.checkLastError(chrome.runtime.lastError);
+ chrome.tabs.sendMessage(tabId, {action, params}, callback);
+ return true;
}
_onApiFrameInformationGet(params, sender) {
@@ -689,11 +695,11 @@ class Backend {
});
}
- async _onApiGetMessageToken() {
+ _onApiGetMessageToken() {
return this.messageToken;
}
- async _onApiGetDefaultAnkiFieldTemplates() {
+ _onApiGetDefaultAnkiFieldTemplates() {
return this.defaultAnkiFieldTemplates;
}
diff --git a/ext/bg/js/japanese.js b/ext/bg/js/japanese.js
index 5c49cca7..5fef27a7 100644
--- a/ext/bg/js/japanese.js
+++ b/ext/bg/js/japanese.js
@@ -82,6 +82,9 @@
const ITERATION_MARK_CODE_POINT = 0x3005;
+ const HIRAGANA_SMALL_TSU_CODE_POINT = 0x3063;
+ const KATAKANA_SMALL_TSU_CODE_POINT = 0x30c3;
+ const KANA_PROLONGED_SOUND_MARK_CODE_POINT = 0x30fc;
// Existing functions
@@ -372,6 +375,40 @@
}
+ // Miscellaneous
+
+ function collapseEmphaticSequences(text, fullCollapse, sourceMap=null) {
+ let result = '';
+ let collapseCodePoint = -1;
+ const hasSourceMap = (sourceMap !== null);
+ for (const char of text) {
+ const c = char.codePointAt(0);
+ if (
+ c === HIRAGANA_SMALL_TSU_CODE_POINT ||
+ c === KATAKANA_SMALL_TSU_CODE_POINT ||
+ c === KANA_PROLONGED_SOUND_MARK_CODE_POINT
+ ) {
+ if (collapseCodePoint !== c) {
+ collapseCodePoint = c;
+ if (!fullCollapse) {
+ result += char;
+ continue;
+ }
+ }
+ } else {
+ collapseCodePoint = -1;
+ result += char;
+ continue;
+ }
+
+ if (hasSourceMap) {
+ sourceMap.combine(Math.max(0, result.length - 1), 1);
+ }
+ }
+ return result;
+ }
+
+
// Exports
Object.assign(jp, {
@@ -383,6 +420,7 @@
convertHalfWidthKanaToFullWidth,
convertAlphabeticToKana,
distributeFurigana,
- distributeFuriganaInflected
+ distributeFuriganaInflected,
+ collapseEmphaticSequences
});
})();
diff --git a/ext/bg/js/options.js b/ext/bg/js/options.js
index 20df2a68..f3e5f60d 100644
--- a/ext/bg/js/options.js
+++ b/ext/bg/js/options.js
@@ -170,7 +170,8 @@ function profileOptionsCreateDefaults() {
convertNumericCharacters: 'false',
convertAlphabeticCharacters: 'false',
convertHiraganaToKatakana: 'false',
- convertKatakanaToHiragana: 'variant'
+ convertKatakanaToHiragana: 'variant',
+ collapseEmphaticSequences: 'false'
},
dictionaries: {},
diff --git a/ext/bg/js/search.js b/ext/bg/js/search.js
index 2ba3e468..871c576b 100644
--- a/ext/bg/js/search.js
+++ b/ext/bg/js/search.js
@@ -208,7 +208,7 @@ class DisplaySearch extends Display {
onCopy() {
// ignore copy from search page
- this.clipboardMonitor.setPreviousText(document.getSelection().toString().trim());
+ this.clipboardMonitor.setPreviousText(window.getSelection().toString().trim());
}
onExternalSearchUpdate({text}) {
diff --git a/ext/bg/js/settings/main.js b/ext/bg/js/settings/main.js
index 8fd94562..308e92eb 100644
--- a/ext/bg/js/settings/main.js
+++ b/ext/bg/js/settings/main.js
@@ -118,6 +118,7 @@ async function formRead(options) {
options.translation.convertAlphabeticCharacters = $('#translation-convert-alphabetic-characters').val();
options.translation.convertHiraganaToKatakana = $('#translation-convert-hiragana-to-katakana').val();
options.translation.convertKatakanaToHiragana = $('#translation-convert-katakana-to-hiragana').val();
+ options.translation.collapseEmphaticSequences = $('#translation-collapse-emphatic-sequences').val();
options.parsing.enableScanningParser = $('#parsing-scan-enable').prop('checked');
options.parsing.enableMecabParser = $('#parsing-mecab-enable').prop('checked');
@@ -199,6 +200,7 @@ async function formWrite(options) {
$('#translation-convert-alphabetic-characters').val(options.translation.convertAlphabeticCharacters);
$('#translation-convert-hiragana-to-katakana').val(options.translation.convertHiraganaToKatakana);
$('#translation-convert-katakana-to-hiragana').val(options.translation.convertKatakanaToHiragana);
+ $('#translation-collapse-emphatic-sequences').val(options.translation.collapseEmphaticSequences);
$('#parsing-scan-enable').prop('checked', options.parsing.enableScanningParser);
$('#parsing-mecab-enable').prop('checked', options.parsing.enableMecabParser);
diff --git a/ext/bg/js/translator.js b/ext/bg/js/translator.js
index e4441384..aaa1a0ec 100644
--- a/ext/bg/js/translator.js
+++ b/ext/bg/js/translator.js
@@ -347,17 +347,27 @@ class Translator {
getAllDeinflections(text, options) {
const translationOptions = options.translation;
+ const collapseEmphaticOptions = [[false, false]];
+ switch (translationOptions.collapseEmphaticSequences) {
+ case 'true':
+ collapseEmphaticOptions.push([true, false]);
+ break;
+ case 'full':
+ collapseEmphaticOptions.push([true, false], [true, true]);
+ break;
+ }
const textOptionVariantArray = [
Translator.getTextOptionEntryVariants(translationOptions.convertHalfWidthCharacters),
Translator.getTextOptionEntryVariants(translationOptions.convertNumericCharacters),
Translator.getTextOptionEntryVariants(translationOptions.convertAlphabeticCharacters),
Translator.getTextOptionEntryVariants(translationOptions.convertHiraganaToKatakana),
- Translator.getTextOptionEntryVariants(translationOptions.convertKatakanaToHiragana)
+ Translator.getTextOptionEntryVariants(translationOptions.convertKatakanaToHiragana),
+ collapseEmphaticOptions
];
const deinflections = [];
const used = new Set();
- for (const [halfWidth, numeric, alphabetic, katakana, hiragana] of Translator.getArrayVariants(textOptionVariantArray)) {
+ for (const [halfWidth, numeric, alphabetic, katakana, hiragana, [collapseEmphatic, collapseEmphaticFull]] of Translator.getArrayVariants(textOptionVariantArray)) {
let text2 = text;
const sourceMap = new TextSourceMap(text2);
if (halfWidth) {
@@ -375,6 +385,9 @@ class Translator {
if (hiragana) {
text2 = jp.convertKatakanaToHiragana(text2);
}
+ if (collapseEmphatic) {
+ text2 = jp.collapseEmphaticSequences(text2, collapseEmphaticFull, sourceMap);
+ }
for (let i = text2.length; i > 0; --i) {
const text2Substring = text2.substring(0, i);
diff --git a/ext/bg/settings.html b/ext/bg/settings.html
index 1297a9cc..96c1db82 100644
--- a/ext/bg/settings.html
+++ b/ext/bg/settings.html
@@ -427,7 +427,7 @@
<p class="help-block">
The conversion options below are listed in the order that the conversions are applied to the input text.
- Each conversion has three possible values:
+ Conversions commonly have three possible values:
</p>
<ul class="help-block">
@@ -490,6 +490,15 @@
<option value="variant">Use both variants</option>
</select>
</div>
+
+ <div class="form-group">
+ <label for="translation-collapse-emphatic-sequences">Collapse emphatic character sequences <span class="label-light">(すっっごーーい &rarr; すっごーい / すごい)</span></label>
+ <select class="form-control" id="translation-collapse-emphatic-sequences">
+ <option value="false">Disabled</option>
+ <option value="true">Collapse into single character</option>
+ <option value="full">Remove all characters</option>
+ </select>
+ </div>
</div>
<div id="popup-content-scanning">
diff --git a/ext/fg/js/float.js b/ext/fg/js/float.js
index 77e5ea0a..5c2c50c2 100644
--- a/ext/fg/js/float.js
+++ b/ext/fg/js/float.js
@@ -17,7 +17,7 @@
/* global
* Display
- * apiForward
+ * apiBroadcastTab
* apiGetMessageToken
* popupNestedInitialize
*/
@@ -79,7 +79,7 @@ class DisplayFloat extends Display {
this.setContentScale(scale);
- apiForward('popupPrepareCompleted', {targetPopupId: this._popupId});
+ apiBroadcastTab('popupPrepareCompleted', {targetPopupId: this._popupId});
}
onError(error) {
@@ -180,7 +180,7 @@ class DisplayFloat extends Display {
},
2000
);
- apiForward('requestDocumentInformationBroadcast', {uniqueId});
+ apiBroadcastTab('requestDocumentInformationBroadcast', {uniqueId});
const {title} = await promise;
return title;
diff --git a/ext/fg/js/frame-offset-forwarder.js b/ext/fg/js/frame-offset-forwarder.js
index b3c10bb8..c658c55a 100644
--- a/ext/fg/js/frame-offset-forwarder.js
+++ b/ext/fg/js/frame-offset-forwarder.js
@@ -16,7 +16,7 @@
*/
/* global
- * apiForward
+ * apiBroadcastTab
*/
class FrameOffsetForwarder {
@@ -96,6 +96,6 @@ class FrameOffsetForwarder {
}
_forwardFrameOffsetOrigin(offset, uniqueId) {
- apiForward('frameOffset', {offset, uniqueId});
+ apiBroadcastTab('frameOffset', {offset, uniqueId});
}
}
diff --git a/ext/fg/js/frontend-initialize.js b/ext/fg/js/frontend-initialize.js
index 0a586ff9..5af7fdf0 100644
--- a/ext/fg/js/frontend-initialize.js
+++ b/ext/fg/js/frontend-initialize.js
@@ -20,7 +20,7 @@
* Frontend
* PopupProxy
* PopupProxyHost
- * apiForward
+ * apiBroadcastTab
* apiOptionsGet
*/
@@ -43,7 +43,7 @@ async function main() {
}
}
);
- apiForward('rootPopupRequestInformationBroadcast');
+ apiBroadcastTab('rootPopupRequestInformationBroadcast');
const {popupId, frameId} = await rootPopupInformationPromise;
const frameOffsetForwarder = new FrameOffsetForwarder();
diff --git a/ext/fg/js/frontend.js b/ext/fg/js/frontend.js
index 6fbbd0fb..95427c4c 100644
--- a/ext/fg/js/frontend.js
+++ b/ext/fg/js/frontend.js
@@ -17,7 +17,7 @@
/* global
* TextScanner
- * apiForward
+ * apiBroadcastTab
* apiGetZoom
* apiKanjiFind
* apiOptionsGet
@@ -43,7 +43,7 @@ class Frontend extends TextScanner {
this._pageZoomFactor = 1.0;
this._contentScale = 1.0;
- this._orphaned = true;
+ this._orphaned = false;
this._lastShowPromise = Promise.resolve();
this._windowMessageHandlers = new Map([
@@ -260,12 +260,12 @@ class Frontend extends TextScanner {
_broadcastRootPopupInformation() {
if (!this.popup.isProxy() && this.popup.depth === 0) {
- apiForward('rootPopupInformation', {popupId: this.popup.id, frameId: this.popup.frameId});
+ apiBroadcastTab('rootPopupInformation', {popupId: this.popup.id, frameId: this.popup.frameId});
}
}
_broadcastDocumentInformation(uniqueId) {
- apiForward('documentInformationBroadcast', {
+ apiBroadcastTab('documentInformationBroadcast', {
uniqueId,
frameId: this.popup.frameId,
title: document.title
diff --git a/ext/mixed/css/display.css b/ext/mixed/css/display.css
index 92ba52c6..d1a54064 100644
--- a/ext/mixed/css/display.css
+++ b/ext/mixed/css/display.css
@@ -297,13 +297,13 @@ button.action-button {
content: "\3001";
}
-.term-expression-list[data-multi=true]>.term-expression:last-of-type:after {
+.entry[data-expression-multi=true] .term-expression-list>.term-expression:last-of-type:after {
font-size: 2em;
content: "\3000";
visibility: hidden;
}
-.term-expression-list[data-multi=true] .term-expression-details {
+.entry[data-expression-multi=true] .term-expression-list .term-expression-details {
display: inline-block;
position: relative;
width: 0;
@@ -312,21 +312,21 @@ button.action-button {
z-index: 1;
}
-.term-expression-list[data-multi=true] .term-expression:hover .term-expression-details {
+.entry[data-expression-multi=true] .term-expression:hover .term-expression-details {
visibility: visible;
}
-.term-expression-list[data-multi=true] .term-expression-details>.action-play-audio {
+.entry[data-expression-multi=true] .term-expression-list .term-expression-details>.action-play-audio {
position: absolute;
left: 0;
bottom: 0.5em;
}
-.term-expression-list:not([data-multi=true]) .term-expression-details>.action-play-audio {
+.entry:not([data-expression-multi=true]) .term-expression-list .term-expression-details>.action-play-audio {
display: none;
}
-.term-expression-list[data-multi=true] .term-expression-details>.tags {
+.entry[data-expression-multi=true] .term-expression-list .term-expression-details>.tags {
display: block;
position: absolute;
left: 0;
@@ -334,7 +334,7 @@ button.action-button {
white-space: nowrap;
}
-.term-expression-list[data-multi=true] .term-expression-details>.frequencies {
+.entry[data-expression-multi=true] .term-expression-list .term-expression-details>.frequencies {
display: block;
position: absolute;
left: 0;
@@ -364,19 +364,19 @@ button.action-button {
list-style-type: circle;
}
-.term-definition-only-list[data-count="0"] {
+.term-definition-disambiguation-list[data-count="0"] {
display: none;
}
-.term-definition-only-list:before {
+.term-definition-disambiguation-list:before {
content: "(";
}
-.term-definition-only-list:after {
+.term-definition-disambiguation-list:after {
content: " only)";
}
-.term-definition-only+.term-definition-only:before {
+.term-definition-disambiguation+.term-definition-disambiguation:before {
content: ", ";
}
@@ -398,7 +398,7 @@ button.action-button {
}
:root[data-compact-glossaries=true] .term-definition-tag-list,
-:root[data-compact-glossaries=true] .term-definition-only-list:not([data-count="0"]) {
+:root[data-compact-glossaries=true] .term-definition-disambiguation-list:not([data-count="0"]) {
display: inline;
}
diff --git a/ext/mixed/display-templates.html b/ext/mixed/display-templates.html
index b8d52d15..3baa8293 100644
--- a/ext/mixed/display-templates.html
+++ b/ext/mixed/display-templates.html
@@ -30,10 +30,10 @@
</div></div></template>
<template id="term-definition-item-template"><li class="term-definition-item">
<div class="term-definition-tag-list tag-list"></div>
- <div class="term-definition-only-list"></div>
+ <div class="term-definition-disambiguation-list"></div>
<ul class="term-glossary-list"></ul>
</li></template>
-<template id="term-definition-only-template"><span class="term-definition-only"></span></template>
+<template id="term-definition-disambiguation-template"><span class="term-definition-disambiguation"></span></template>
<template id="term-glossary-item-template"><li class="term-glossary-item"><span class="term-glossary-separator"> </span><span class="term-glossary"></span></li></template>
<template id="term-reason-template"><span class="term-reason"></span><span class="term-reason-separator"> </span></template>
diff --git a/ext/mixed/js/api.js b/ext/mixed/js/api.js
index 066077cf..50b285a5 100644
--- a/ext/mixed/js/api.js
+++ b/ext/mixed/js/api.js
@@ -80,8 +80,8 @@ function apiScreenshotGet(options) {
return _apiInvoke('screenshotGet', {options});
}
-function apiForward(action, params) {
- return _apiInvoke('forward', {action, params});
+function apiBroadcastTab(action, params) {
+ return _apiInvoke('broadcastTab', {action, params});
}
function apiFrameInformationGet() {
diff --git a/ext/mixed/js/display-generator.js b/ext/mixed/js/display-generator.js
index b0cc2478..0f991362 100644
--- a/ext/mixed/js/display-generator.js
+++ b/ext/mixed/js/display-generator.js
@@ -43,13 +43,15 @@ class DisplayGenerator {
const debugInfoContainer = node.querySelector('.debug-info');
const bodyContainer = node.querySelector('.term-entry-body');
- const pitches = DisplayGenerator._getPitchInfos(details);
+ const {termTags, expressions, definitions} = details;
+
+ const pitches = this._getPitchInfos(details);
const pitchCount = pitches.reduce((i, v) => i + v[1].length, 0);
- const expressionMulti = Array.isArray(details.expressions);
- const definitionMulti = Array.isArray(details.definitions);
- const expressionCount = expressionMulti ? details.expressions.length : 1;
- const definitionCount = definitionMulti ? details.definitions.length : 1;
+ const expressionMulti = Array.isArray(expressions);
+ const definitionMulti = Array.isArray(definitions);
+ const expressionCount = expressionMulti ? expressions.length : 1;
+ const definitionCount = definitionMulti ? definitions.length : 1;
const uniqueExpressionCount = Array.isArray(details.expression) ? new Set(details.expression).size : 1;
node.dataset.expressionMulti = `${expressionMulti}`;
@@ -65,15 +67,56 @@ class DisplayGenerator {
(pitches.length > 0 ? 1 : 0)
}`;
- const termTags = details.termTags;
- let expressions = details.expressions;
- expressions = Array.isArray(expressions) ? expressions.map((e) => [e, termTags]) : null;
+ this._appendMultiple(expressionsContainer, this._createTermExpression.bind(this), expressionMulti ? expressions : [details], termTags);
+ this._appendMultiple(reasonsContainer, this._createTermReason.bind(this), details.reasons);
+ this._appendMultiple(frequenciesContainer, this._createFrequencyTag.bind(this), details.frequencies);
+ this._appendMultiple(pitchesContainer, this._createPitches.bind(this), pitches);
+ this._appendMultiple(definitionsContainer, this._createTermDefinitionItem.bind(this), definitionMulti ? definitions : [details]);
+
+ if (debugInfoContainer !== null) {
+ debugInfoContainer.textContent = JSON.stringify(details, null, 4);
+ }
+
+ return node;
+ }
+
+ createKanjiEntry(details) {
+ const node = this._templateHandler.instantiate('kanji-entry');
+
+ const glyphContainer = node.querySelector('.kanji-glyph');
+ const frequenciesContainer = node.querySelector('.frequencies');
+ const tagContainer = node.querySelector('.tags');
+ const glossaryContainer = node.querySelector('.kanji-glossary-list');
+ const chineseReadingsContainer = node.querySelector('.kanji-readings-chinese');
+ const japaneseReadingsContainer = node.querySelector('.kanji-readings-japanese');
+ const statisticsContainer = node.querySelector('.kanji-statistics');
+ const classificationsContainer = node.querySelector('.kanji-classifications');
+ const codepointsContainer = node.querySelector('.kanji-codepoints');
+ const dictionaryIndicesContainer = node.querySelector('.kanji-dictionary-indices');
+ const debugInfoContainer = node.querySelector('.debug-info');
+
+ if (glyphContainer !== null) {
+ glyphContainer.textContent = details.character;
+ }
- DisplayGenerator._appendMultiple(expressionsContainer, this.createTermExpression.bind(this), expressions, [[details, termTags]]);
- DisplayGenerator._appendMultiple(reasonsContainer, this.createTermReason.bind(this), details.reasons);
- DisplayGenerator._appendMultiple(frequenciesContainer, this.createFrequencyTag.bind(this), details.frequencies);
- DisplayGenerator._appendMultiple(pitchesContainer, this.createPitches.bind(this), pitches);
- DisplayGenerator._appendMultiple(definitionsContainer, this.createTermDefinitionItem.bind(this), details.definitions, [details]);
+ this._appendMultiple(frequenciesContainer, this._createFrequencyTag.bind(this), details.frequencies);
+ this._appendMultiple(tagContainer, this._createTag.bind(this), details.tags);
+ this._appendMultiple(glossaryContainer, this._createKanjiGlossaryItem.bind(this), details.glossary);
+ this._appendMultiple(chineseReadingsContainer, this._createKanjiReading.bind(this), details.onyomi);
+ this._appendMultiple(japaneseReadingsContainer, this._createKanjiReading.bind(this), details.kunyomi);
+
+ if (statisticsContainer !== null) {
+ statisticsContainer.appendChild(this._createKanjiInfoTable(details.stats.misc));
+ }
+ if (classificationsContainer !== null) {
+ classificationsContainer.appendChild(this._createKanjiInfoTable(details.stats.class));
+ }
+ if (codepointsContainer !== null) {
+ codepointsContainer.appendChild(this._createKanjiInfoTable(details.stats.code));
+ }
+ if (dictionaryIndicesContainer !== null) {
+ dictionaryIndicesContainer.appendChild(this._createKanjiInfoTable(details.stats.index));
+ }
if (debugInfoContainer !== null) {
debugInfoContainer.textContent = JSON.stringify(details, null, 4);
@@ -82,7 +125,9 @@ class DisplayGenerator {
return node;
}
- createTermExpression([details, termTags]) {
+ // Private
+
+ _createTermExpression(details, termTags) {
const node = this._templateHandler.instantiate('term-expression');
const expressionContainer = node.querySelector('.term-expression-text');
@@ -99,7 +144,7 @@ class DisplayGenerator {
// This case should not occur
furiganaSegments = [{text: details.expression, furigana: details.reading}];
}
- DisplayGenerator._appendFurigana(expressionContainer, furiganaSegments, this._appendKanjiLinks.bind(this));
+ this._appendFurigana(expressionContainer, furiganaSegments, this._appendKanjiLinks.bind(this));
}
if (!Array.isArray(termTags)) {
@@ -109,14 +154,14 @@ class DisplayGenerator {
const searchQueries = [details.expression, details.reading]
.filter((x) => !!x)
.map((x) => ({query: x}));
- DisplayGenerator._appendMultiple(tagContainer, this.createTag.bind(this), termTags);
- DisplayGenerator._appendMultiple(tagContainer, this.createSearchTag.bind(this), searchQueries);
- DisplayGenerator._appendMultiple(frequencyContainer, this.createFrequencyTag.bind(this), details.frequencies);
+ this._appendMultiple(tagContainer, this._createTag.bind(this), termTags);
+ this._appendMultiple(tagContainer, this._createSearchTag.bind(this), searchQueries);
+ this._appendMultiple(frequencyContainer, this._createFrequencyTag.bind(this), details.frequencies);
return node;
}
- createTermReason(reason) {
+ _createTermReason(reason) {
const fragment = this._templateHandler.instantiateFragment('term-reason');
const node = fragment.querySelector('.term-reason');
node.textContent = reason;
@@ -124,39 +169,39 @@ class DisplayGenerator {
return fragment;
}
- createTermDefinitionItem(details) {
+ _createTermDefinitionItem(details) {
const node = this._templateHandler.instantiate('term-definition-item');
const tagListContainer = node.querySelector('.term-definition-tag-list');
- const onlyListContainer = node.querySelector('.term-definition-only-list');
+ const onlyListContainer = node.querySelector('.term-definition-disambiguation-list');
const glossaryContainer = node.querySelector('.term-glossary-list');
node.dataset.dictionary = details.dictionary;
- DisplayGenerator._appendMultiple(tagListContainer, this.createTag.bind(this), details.definitionTags);
- DisplayGenerator._appendMultiple(onlyListContainer, this.createTermOnly.bind(this), details.only);
- DisplayGenerator._appendMultiple(glossaryContainer, this.createTermGlossaryItem.bind(this), details.glossary);
+ this._appendMultiple(tagListContainer, this._createTag.bind(this), details.definitionTags);
+ this._appendMultiple(onlyListContainer, this._createTermDisambiguation.bind(this), details.only);
+ this._appendMultiple(glossaryContainer, this._createTermGlossaryItem.bind(this), details.glossary);
return node;
}
- createTermGlossaryItem(glossary) {
+ _createTermGlossaryItem(glossary) {
const node = this._templateHandler.instantiate('term-glossary-item');
const container = node.querySelector('.term-glossary');
if (container !== null) {
- DisplayGenerator._appendMultilineText(container, glossary);
+ this._appendMultilineText(container, glossary);
}
return node;
}
- createTermOnly(only) {
- const node = this._templateHandler.instantiate('term-definition-only');
- node.dataset.only = only;
- node.textContent = only;
+ _createTermDisambiguation(disambiguation) {
+ const node = this._templateHandler.instantiate('term-definition-disambiguation');
+ node.dataset.term = disambiguation;
+ node.textContent = disambiguation;
return node;
}
- createKanjiLink(character) {
+ _createKanjiLink(character) {
const node = document.createElement('a');
node.href = '#';
node.className = 'kanji-link';
@@ -164,75 +209,30 @@ class DisplayGenerator {
return node;
}
- createKanjiEntry(details) {
- const node = this._templateHandler.instantiate('kanji-entry');
-
- const glyphContainer = node.querySelector('.kanji-glyph');
- const frequenciesContainer = node.querySelector('.frequencies');
- const tagContainer = node.querySelector('.tags');
- const glossaryContainer = node.querySelector('.kanji-glossary-list');
- const chineseReadingsContainer = node.querySelector('.kanji-readings-chinese');
- const japaneseReadingsContainer = node.querySelector('.kanji-readings-japanese');
- const statisticsContainer = node.querySelector('.kanji-statistics');
- const classificationsContainer = node.querySelector('.kanji-classifications');
- const codepointsContainer = node.querySelector('.kanji-codepoints');
- const dictionaryIndicesContainer = node.querySelector('.kanji-dictionary-indices');
- const debugInfoContainer = node.querySelector('.debug-info');
-
- if (glyphContainer !== null) {
- glyphContainer.textContent = details.character;
- }
-
- DisplayGenerator._appendMultiple(frequenciesContainer, this.createFrequencyTag.bind(this), details.frequencies);
- DisplayGenerator._appendMultiple(tagContainer, this.createTag.bind(this), details.tags);
- DisplayGenerator._appendMultiple(glossaryContainer, this.createKanjiGlossaryItem.bind(this), details.glossary);
- DisplayGenerator._appendMultiple(chineseReadingsContainer, this.createKanjiReading.bind(this), details.onyomi);
- DisplayGenerator._appendMultiple(japaneseReadingsContainer, this.createKanjiReading.bind(this), details.kunyomi);
-
- if (statisticsContainer !== null) {
- statisticsContainer.appendChild(this.createKanjiInfoTable(details.stats.misc));
- }
- if (classificationsContainer !== null) {
- classificationsContainer.appendChild(this.createKanjiInfoTable(details.stats.class));
- }
- if (codepointsContainer !== null) {
- codepointsContainer.appendChild(this.createKanjiInfoTable(details.stats.code));
- }
- if (dictionaryIndicesContainer !== null) {
- dictionaryIndicesContainer.appendChild(this.createKanjiInfoTable(details.stats.index));
- }
-
- if (debugInfoContainer !== null) {
- debugInfoContainer.textContent = JSON.stringify(details, null, 4);
- }
-
- return node;
- }
-
- createKanjiGlossaryItem(glossary) {
+ _createKanjiGlossaryItem(glossary) {
const node = this._templateHandler.instantiate('kanji-glossary-item');
const container = node.querySelector('.kanji-glossary');
if (container !== null) {
- DisplayGenerator._appendMultilineText(container, glossary);
+ this._appendMultilineText(container, glossary);
}
return node;
}
- createKanjiReading(reading) {
+ _createKanjiReading(reading) {
const node = this._templateHandler.instantiate('kanji-reading');
node.textContent = reading;
return node;
}
- createKanjiInfoTable(details) {
+ _createKanjiInfoTable(details) {
const node = this._templateHandler.instantiate('kanji-info-table');
const container = node.querySelector('.kanji-info-table-body');
if (container !== null) {
- const count = DisplayGenerator._appendMultiple(container, this.createKanjiInfoTableItem.bind(this), details);
+ const count = this._appendMultiple(container, this._createKanjiInfoTableItem.bind(this), details);
if (count === 0) {
- const n = this.createKanjiInfoTableItemEmpty();
+ const n = this._createKanjiInfoTableItemEmpty();
container.appendChild(n);
}
}
@@ -240,7 +240,7 @@ class DisplayGenerator {
return node;
}
- createKanjiInfoTableItem(details) {
+ _createKanjiInfoTableItem(details) {
const node = this._templateHandler.instantiate('kanji-info-table-item');
const nameNode = node.querySelector('.kanji-info-table-item-header');
const valueNode = node.querySelector('.kanji-info-table-item-value');
@@ -253,11 +253,11 @@ class DisplayGenerator {
return node;
}
- createKanjiInfoTableItemEmpty() {
+ _createKanjiInfoTableItemEmpty() {
return this._templateHandler.instantiate('kanji-info-table-empty');
}
- createTag(details) {
+ _createTag(details) {
const node = this._templateHandler.instantiate('tag');
const inner = node.querySelector('.tag-inner');
@@ -269,7 +269,7 @@ class DisplayGenerator {
return node;
}
- createSearchTag(details) {
+ _createSearchTag(details) {
const node = this._templateHandler.instantiate('tag-search');
node.textContent = details.query;
@@ -279,7 +279,7 @@ class DisplayGenerator {
return node;
}
- createPitches(details) {
+ _createPitches(details) {
if (!this._termPitchAccentStaticTemplateIsSetup) {
this._termPitchAccentStaticTemplateIsSetup = true;
const t = this._templateHandler.instantiate('term-pitch-accent-static');
@@ -293,16 +293,16 @@ class DisplayGenerator {
node.dataset.pitchesMulti = 'true';
node.dataset.pitchesCount = `${dictionaryPitches.length}`;
- const tag = this.createTag({notes: '', name: dictionary, category: 'pitch-accent-dictionary'});
+ const tag = this._createTag({notes: '', name: dictionary, category: 'pitch-accent-dictionary'});
node.querySelector('.term-pitch-accent-group-tag-list').appendChild(tag);
const n = node.querySelector('.term-pitch-accent-list');
- DisplayGenerator._appendMultiple(n, this.createPitch.bind(this), dictionaryPitches);
+ this._appendMultiple(n, this._createPitch.bind(this), dictionaryPitches);
return node;
}
- createPitch(details) {
+ _createPitch(details) {
const {reading, position, tags, exclusiveExpressions, exclusiveReadings} = details;
const morae = jp.getKanaMorae(reading);
@@ -315,10 +315,10 @@ class DisplayGenerator {
n.textContent = `${position}`;
n = node.querySelector('.term-pitch-accent-tag-list');
- DisplayGenerator._appendMultiple(n, this.createTag.bind(this), tags);
+ this._appendMultiple(n, this._createTag.bind(this), tags);
n = node.querySelector('.term-pitch-accent-disambiguation-list');
- this.createPitchAccentDisambiguations(n, exclusiveExpressions, exclusiveReadings);
+ this._createPitchAccentDisambiguations(n, exclusiveExpressions, exclusiveReadings);
n = node.querySelector('.term-pitch-accent-characters');
for (let i = 0, ii = morae.length; i < ii; ++i) {
@@ -338,13 +338,13 @@ class DisplayGenerator {
}
if (morae.length > 0) {
- this.populatePitchGraph(node.querySelector('.term-pitch-accent-graph'), position, morae);
+ this._populatePitchGraph(node.querySelector('.term-pitch-accent-graph'), position, morae);
}
return node;
}
- createPitchAccentDisambiguations(container, exclusiveExpressions, exclusiveReadings) {
+ _createPitchAccentDisambiguations(container, exclusiveExpressions, exclusiveReadings) {
const templateName = 'term-pitch-accent-disambiguation';
for (const exclusiveExpression of exclusiveExpressions) {
const node = this._templateHandler.instantiate(templateName);
@@ -360,13 +360,12 @@ class DisplayGenerator {
container.appendChild(node);
}
- container.dataset.multi = 'true';
container.dataset.count = `${exclusiveExpressions.length + exclusiveReadings.length}`;
container.dataset.expressionCount = `${exclusiveExpressions.length}`;
container.dataset.readingCount = `${exclusiveReadings.length}`;
}
- populatePitchGraph(svg, position, morae) {
+ _populatePitchGraph(svg, position, morae) {
const svgns = svg.getAttribute('xmlns');
const ii = morae.length;
svg.setAttribute('viewBox', `0 0 ${50 * (ii + 1)} 100`);
@@ -406,7 +405,7 @@ class DisplayGenerator {
path.setAttribute('d', `M${pathPoints.join(' L')}`);
}
- createFrequencyTag(details) {
+ _createFrequencyTag(details) {
const node = this._templateHandler.instantiate('tag-frequency');
let n = node.querySelector('.term-frequency-dictionary-name');
@@ -434,7 +433,7 @@ class DisplayGenerator {
part = '';
}
- const link = this.createKanjiLink(c);
+ const link = this._createKanjiLink(c);
container.appendChild(link);
} else {
part += c;
@@ -445,31 +444,31 @@ class DisplayGenerator {
}
}
- static _appendMultiple(container, createItem, detailsIterable, fallback=[]) {
- if (container === null) { return 0; }
-
- const multi = (
- detailsIterable !== null &&
- typeof detailsIterable === 'object' &&
- typeof detailsIterable[Symbol.iterator] !== 'undefined'
+ _isIterable(value) {
+ return (
+ value !== null &&
+ typeof value === 'object' &&
+ typeof value[Symbol.iterator] !== 'undefined'
);
- if (!multi) { detailsIterable = fallback; }
+ }
+ _appendMultiple(container, createItem, detailsIterable, ...args) {
let count = 0;
- for (const details of detailsIterable) {
- const item = createItem(details);
- if (item === null) { continue; }
- container.appendChild(item);
- ++count;
+ if (container !== null && this._isIterable(detailsIterable)) {
+ for (const details of detailsIterable) {
+ const item = createItem(details, ...args);
+ if (item === null) { continue; }
+ container.appendChild(item);
+ ++count;
+ }
}
- container.dataset.multi = `${multi}`;
container.dataset.count = `${count}`;
return count;
}
- static _appendFurigana(container, segments, addText) {
+ _appendFurigana(container, segments, addText) {
for (const {text, furigana} of segments) {
if (furigana) {
const ruby = document.createElement('ruby');
@@ -484,7 +483,7 @@ class DisplayGenerator {
}
}
- static _appendMultilineText(container, text) {
+ _appendMultilineText(container, text) {
const parts = text.split('\n');
container.appendChild(document.createTextNode(parts[0]));
for (let i = 1, ii = parts.length; i < ii; ++i) {
@@ -493,7 +492,7 @@ class DisplayGenerator {
}
}
- static _getPitchInfos(definition) {
+ _getPitchInfos(definition) {
const results = new Map();
const allExpressions = new Set();
@@ -511,7 +510,7 @@ class DisplayGenerator {
}
for (const {position, tags} of pitches) {
- let pitchInfo = DisplayGenerator._findExistingPitchInfo(reading, position, tags, dictionaryResults);
+ let pitchInfo = this._findExistingPitchInfo(reading, position, tags, dictionaryResults);
if (pitchInfo === null) {
pitchInfo = {expressions: new Set(), reading, position, tags};
dictionaryResults.push(pitchInfo);
@@ -540,12 +539,12 @@ class DisplayGenerator {
return [...results.entries()];
}
- static _findExistingPitchInfo(reading, position, tags, pitchInfoList) {
+ _findExistingPitchInfo(reading, position, tags, pitchInfoList) {
for (const pitchInfo of pitchInfoList) {
if (
pitchInfo.reading === reading &&
pitchInfo.position === position &&
- DisplayGenerator._areTagListsEqual(pitchInfo.tags, tags)
+ this._areTagListsEqual(pitchInfo.tags, tags)
) {
return pitchInfo;
}
@@ -553,7 +552,7 @@ class DisplayGenerator {
return null;
}
- static _areTagListsEqual(tagList1, tagList2) {
+ _areTagListsEqual(tagList1, tagList2) {
const ii = tagList1.length;
if (tagList2.length !== ii) { return false; }
diff --git a/ext/mixed/js/display.js b/ext/mixed/js/display.js
index bf6990a1..63687dc2 100644
--- a/ext/mixed/js/display.js
+++ b/ext/mixed/js/display.js
@@ -22,9 +22,9 @@
* DisplayGenerator
* WindowScroll
* apiAudioGetUri
+ * apiBroadcastTab
* apiDefinitionAdd
* apiDefinitionsAddable
- * apiForward
* apiKanjiFind
* apiNoteView
* apiOptionsGet
@@ -854,7 +854,7 @@ class Display {
}
setPopupVisibleOverride(visible) {
- return apiForward('popupSetVisibleOverride', {visible});
+ return apiBroadcastTab('popupSetVisibleOverride', {visible});
}
setSpinnerVisible(visible) {
diff --git a/ext/mixed/js/text-scanner.js b/ext/mixed/js/text-scanner.js
index a1d96320..e6b9a2e6 100644
--- a/ext/mixed/js/text-scanner.js
+++ b/ext/mixed/js/text-scanner.js
@@ -133,7 +133,7 @@ class TextScanner {
this.preventNextClick = false;
const primaryTouch = e.changedTouches[0];
- if (DOM.isPointInSelection(primaryTouch.clientX, primaryTouch.clientY, this.node.getSelection())) {
+ if (DOM.isPointInSelection(primaryTouch.clientX, primaryTouch.clientY, window.getSelection())) {
return;
}
diff --git a/package-lock.json b/package-lock.json
index 920263d2..8f421a68 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -906,9 +906,9 @@
"dev": true
},
"jsdom": {
- "version": "16.2.1",
- "resolved": "https://registry.npmjs.org/jsdom/-/jsdom-16.2.1.tgz",
- "integrity": "sha512-3p0gHs5EfT7PxW9v8Phz3mrq//4Dy8MQenU/PoKxhdT+c45S7NjIjKbGT3Ph0nkICweE1r36+yaknXA5WfVNAg==",
+ "version": "16.2.2",
+ "resolved": "https://registry.npmjs.org/jsdom/-/jsdom-16.2.2.tgz",
+ "integrity": "sha512-pDFQbcYtKBHxRaP55zGXCJWgFHkDAYbKcsXEK/3Icu9nKYZkutUXfLBwbD+09XDutkYSHcgfQLZ0qvpAAm9mvg==",
"dev": true,
"requires": {
"abab": "^2.0.3",
@@ -931,11 +931,11 @@
"tough-cookie": "^3.0.1",
"w3c-hr-time": "^1.0.2",
"w3c-xmlserializer": "^2.0.0",
- "webidl-conversions": "^5.0.0",
+ "webidl-conversions": "^6.0.0",
"whatwg-encoding": "^1.0.5",
"whatwg-mimetype": "^2.3.0",
"whatwg-url": "^8.0.0",
- "ws": "^7.2.1",
+ "ws": "^7.2.3",
"xml-name-validator": "^3.0.0"
},
"dependencies": {
@@ -946,6 +946,14 @@
"dev": true,
"requires": {
"webidl-conversions": "^5.0.0"
+ },
+ "dependencies": {
+ "webidl-conversions": {
+ "version": "5.0.0",
+ "resolved": "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-5.0.0.tgz",
+ "integrity": "sha512-VlZwKPCkYKxQgeSbH5EyngOmRp7Ww7I9rQLERETtf5ofd9pGeswWiOtogpEO850jziPRarreGxn5QIiTqpb2wA==",
+ "dev": true
+ }
}
},
"tr46": {
@@ -958,9 +966,9 @@
}
},
"webidl-conversions": {
- "version": "5.0.0",
- "resolved": "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-5.0.0.tgz",
- "integrity": "sha512-VlZwKPCkYKxQgeSbH5EyngOmRp7Ww7I9rQLERETtf5ofd9pGeswWiOtogpEO850jziPRarreGxn5QIiTqpb2wA==",
+ "version": "6.0.0",
+ "resolved": "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-6.0.0.tgz",
+ "integrity": "sha512-jTZAeJnc6D+yAOjygbJOs33kVQIk5H6fj9SFDOhIKjsf9HiAzL/c+tAJsc8ASWafvhNkH+wJZms47pmajkhatA==",
"dev": true
},
"whatwg-url": {
@@ -972,6 +980,14 @@
"lodash.sortby": "^4.7.0",
"tr46": "^2.0.0",
"webidl-conversions": "^5.0.0"
+ },
+ "dependencies": {
+ "webidl-conversions": {
+ "version": "5.0.0",
+ "resolved": "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-5.0.0.tgz",
+ "integrity": "sha512-VlZwKPCkYKxQgeSbH5EyngOmRp7Ww7I9rQLERETtf5ofd9pGeswWiOtogpEO850jziPRarreGxn5QIiTqpb2wA==",
+ "dev": true
+ }
}
}
}
@@ -1199,9 +1215,9 @@
"dev": true
},
"psl": {
- "version": "1.7.0",
- "resolved": "https://registry.npmjs.org/psl/-/psl-1.7.0.tgz",
- "integrity": "sha512-5NsSEDv8zY70ScRnOTn7bK7eanl2MvFrOrS/R6x+dBt5g1ghnj9Zv90kO8GwT8gxcu2ANyFprnFYB85IogIJOQ==",
+ "version": "1.8.0",
+ "resolved": "https://registry.npmjs.org/psl/-/psl-1.8.0.tgz",
+ "integrity": "sha512-RIdOzyoavK+hA18OGGWDqUTsCLhtA7IcZ/6NCs4fFJaHBDab+pDDmDIByWFRQJq2Cd7r1OoQxBGKOaztq+hjIQ==",
"dev": true
},
"punycode": {
@@ -1362,9 +1378,9 @@
"dev": true
},
"saxes": {
- "version": "5.0.0",
- "resolved": "https://registry.npmjs.org/saxes/-/saxes-5.0.0.tgz",
- "integrity": "sha512-LXTZygxhf8lfwKaTP/8N9CsVdjTlea3teze4lL6u37ivbgGbV0GGMuNtS/I9rnD/HC2/txUM7Df4S2LVl1qhiA==",
+ "version": "5.0.1",
+ "resolved": "https://registry.npmjs.org/saxes/-/saxes-5.0.1.tgz",
+ "integrity": "sha512-5LBh1Tls8c9xgGjw3QrMwETmTMVk0oFgvrFSvWx62llR2hcEInrKNZ2GZCCuuy2lvWrdl5jhbpeqc5hRYKFOcw==",
"dev": true,
"requires": {
"xmlchars": "^2.2.0"
diff --git a/package.json b/package.json
index b02ec179..0729cda1 100644
--- a/package.json
+++ b/package.json
@@ -30,6 +30,6 @@
"eslint": "^6.8.0",
"eslint-plugin-no-unsanitized": "^3.0.2",
"fake-indexeddb": "^3.0.0",
- "jsdom": "^16.2.1"
+ "jsdom": "^16.2.2"
}
}
diff --git a/test/test-japanese.js b/test/test-japanese.js
index f4b084ac..89e41c36 100644
--- a/test/test-japanese.js
+++ b/test/test-japanese.js
@@ -393,6 +393,59 @@ function testDistributeFuriganaInflected() {
}
}
+function testCollapseEmphaticSequences() {
+ const data = [
+ [['かこい', false], ['かこい', [1, 1, 1]]],
+ [['かこい', true], ['かこい', [1, 1, 1]]],
+ [['かっこい', false], ['かっこい', [1, 1, 1, 1]]],
+ [['かっこい', true], ['かこい', [2, 1, 1]]],
+ [['かっっこい', false], ['かっこい', [1, 2, 1, 1]]],
+ [['かっっこい', true], ['かこい', [3, 1, 1]]],
+ [['かっっっこい', false], ['かっこい', [1, 3, 1, 1]]],
+ [['かっっっこい', true], ['かこい', [4, 1, 1]]],
+
+ [['こい', false], ['こい', [1, 1]]],
+ [['こい', true], ['こい', [1, 1]]],
+ [['っこい', false], ['っこい', [1, 1, 1]]],
+ [['っこい', true], ['こい', [2, 1]]],
+ [['っっこい', false], ['っこい', [2, 1, 1]]],
+ [['っっこい', true], ['こい', [3, 1]]],
+ [['っっっこい', false], ['っこい', [3, 1, 1]]],
+ [['っっっこい', true], ['こい', [4, 1]]],
+
+ [['すごい', false], ['すごい', [1, 1, 1]]],
+ [['すごい', true], ['すごい', [1, 1, 1]]],
+ [['すごーい', false], ['すごーい', [1, 1, 1, 1]]],
+ [['すごーい', true], ['すごい', [1, 2, 1]]],
+ [['すごーーい', false], ['すごーい', [1, 1, 2, 1]]],
+ [['すごーーい', true], ['すごい', [1, 3, 1]]],
+ [['すっごーい', false], ['すっごーい', [1, 1, 1, 1, 1]]],
+ [['すっごーい', true], ['すごい', [2, 2, 1]]],
+ [['すっっごーーい', false], ['すっごーい', [1, 2, 1, 2, 1]]],
+ [['すっっごーーい', true], ['すごい', [3, 3, 1]]],
+
+ [['', false], ['', []]],
+ [['', true], ['', []]],
+ [['っ', false], ['っ', [1]]],
+ [['っ', true], ['', [1]]],
+ [['っっ', false], ['っ', [2]]],
+ [['っっ', true], ['', [2]]],
+ [['っっっ', false], ['っ', [3]]],
+ [['っっっ', true], ['', [3]]]
+ ];
+
+ for (const [[text, fullCollapse], [expected, expectedSourceMapping]] of data) {
+ const sourceMap = new TextSourceMap(text);
+ const actual1 = jp.collapseEmphaticSequences(text, fullCollapse, null);
+ const actual2 = jp.collapseEmphaticSequences(text, fullCollapse, sourceMap);
+ assert.strictEqual(actual1, expected);
+ assert.strictEqual(actual2, expected);
+ if (typeof expectedSourceMapping !== 'undefined') {
+ assert.ok(sourceMap.equals(new TextSourceMap(text, expectedSourceMapping)));
+ }
+ }
+}
+
function testIsMoraPitchHigh() {
const data = [
[[0, 0], false],
@@ -462,6 +515,7 @@ function main() {
testConvertAlphabeticToKana();
testDistributeFurigana();
testDistributeFuriganaInflected();
+ testCollapseEmphaticSequences();
testIsMoraPitchHigh();
testGetKanaMorae();
}