pinyin-ime 1.0.0 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { P as PinyinDict } from '../dist-bllJYkRT.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* 合并多个 {@link PinyinDict}:对每个 key 合并其 value 数组;重复词条取较大 `f`。
|
|
5
|
+
*
|
|
6
|
+
* @param dicts - 至少一个词典
|
|
7
|
+
* @returns 新的顶层对象(不修改入参)
|
|
8
|
+
*/
|
|
9
|
+
declare function mergePinyinDicts(...dicts: PinyinDict[]): PinyinDict;
|
|
10
|
+
declare const dict: PinyinDict;
|
|
11
|
+
|
|
12
|
+
export { dict, mergePinyinDicts };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* One candidate word or phrase with an optional corpus frequency weight.
|
|
3
|
+
*/
|
|
4
|
+
type DictEntry = {
|
|
5
|
+
w: string;
|
|
6
|
+
f: number;
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* Map from lowercase pinyin key to ranked candidates (larger corpora use long keys).
|
|
10
|
+
*/
|
|
11
|
+
type PinyinDict = Record<string, DictEntry[]>;
|
|
12
|
+
|
|
13
|
+
export type { PinyinDict as P };
|
package/dist/index.d.ts
CHANGED
|
@@ -611,6 +611,9 @@ declare class PinyinIMEEditor extends LitElement {
|
|
|
611
611
|
* @returns 简短说明句
|
|
612
612
|
*/
|
|
613
613
|
private _modeDescription;
|
|
614
|
+
/**
|
|
615
|
+
* 渲染内部输入框、中/英文模式角标(仅在 {@link PinyinIMEEditor.enabled} 为真时)及拼音候选弹层。
|
|
616
|
+
*/
|
|
614
617
|
render(): lit.TemplateResult<1>;
|
|
615
618
|
private _onNativeInput;
|
|
616
619
|
/**
|
package/dist/index.js
CHANGED
|
@@ -201,16 +201,16 @@ function joinClassNames(...parts){return parts.filter(Boolean).join(" ")}var _de
|
|
|
201
201
|
cursor: default;\r
|
|
202
202
|
opacity: 0.5;\r
|
|
203
203
|
}\r
|
|
204
|
-
`;var defaultGoogleDictPromise=null;function getSharedDefaultGoogleDict(){return defaultGoogleDictPromise??=(async()=>{try{return (await import('pinyin-ime/dictionary/google_pinyin_dict')).dict}catch{throw new Error("Failed to import default google dictionary")}})()}function dictionaryLoadDevLog(...args){}var RESERVED_ATTRIBUTES=new Set(["value","editor-type","page-size","enabled","class","dictionary-load","popup-position"]),PinyinIMEEditor=class extends i3{static styles=[r(PINYIN_IME_STYLE_TEXT)];static properties={value:{type:String,converter:{fromAttribute(v2){return v2??""}}},editorType:{type:String,attribute:"editor-type",converter:{fromAttribute(value){return parseEditorTypeFromAttribute(value)}}},pageSize:{type:Number,attribute:"page-size",converter:{fromAttribute(value){return parsePageSizeFromAttribute(value)}}},enabled:{type:Boolean,converter:{fromAttribute(value){return parseEnabledFromAttribute(value)},toAttribute(value){return value?null:"false"}},reflect:true},popupPosition:{type:String,attribute:"popup-position",converter:{fromAttribute(value){return parsePopupPlacementFromAttribute(value)},toAttribute(value){return popupPlacementToAttribute(value)}}},getDictionary:{attribute:false}};inputRef=e4();_controller=null;_unsub=null;_cleanupNativeListeners=null;_customEngine=null;_dictionaryState="idle";_dictionaryLoadSeq=0;_position=null;_idleCallbackHandle=null;_idleCallbackIsRic=false;_deferredFocusCleanup=null;_onWinResize=()=>{this._syncPosition(),this.requestUpdate();};constructor(){super(),this.value="",this.editorType="input",this.enabled=true,this.pageSize=5,this.popupPosition="top";}focus(options){let target=this.inputRef.value;if(target){target.focus(options);return}super.focus(options);}blur(){let target=this.inputRef.value;if(target){target.blur();return}super.blur();}_resolvedEngine(){return this._customEngine}_syncPosition(){let el=this.inputRef.value,snap=this._controller?.getSnapshot();if(!el||!snap?.hasActiveComposition){this._position=null;return}let rect=el.getBoundingClientRect();this._position={top:rect.top,left:rect.left,width:rect.width,height:rect.height};}_popupStyle(position){return this.popupPosition==="bottom"?`top: ${position.top+position.height+2}px; left: ${position.left}px; width: ${position.width}px;`:this.popupPosition==="left"?`top: ${position.top}px; left: ${position.left-2}px; width: ${position.width}px; transform: translateX(-100%);`:this.popupPosition==="right"?`top: ${position.top}px; left: ${position.left+position.width+2}px; width: ${position.width}px;`:`top: ${position.top}px; left: ${position.left}px; width: ${position.width}px; transform: translateY(-100%) translateY(-2px);`}_getPassThroughAttributes(){let attrs={};for(let i5=0;i5<this.attributes.length;i5++){let a3=this.attributes[i5];RESERVED_ATTRIBUTES.has(a3.name)||(attrs[a3.name]=a3.value);}return attrs}_importDefaultGoogleDict(){return getSharedDefaultGoogleDict()}_cancelDeferredDictionaryWaiters(){this._idleCallbackHandle!==null&&(this._idleCallbackIsRic&&typeof cancelIdleCallback=="function"?cancelIdleCallback(this._idleCallbackHandle):clearTimeout(this._idleCallbackHandle),this._idleCallbackHandle=null),this._deferredFocusCleanup?.(),this._deferredFocusCleanup=null;}_scheduleDeferredIdleCallback(){if(this._dictionaryState==="loading"||this._dictionaryState==="ready"){dictionaryLoadDevLog("scheduleDeferredIdle skipped",{state:this._dictionaryState});return}if(this._idleCallbackHandle!==null){return}let ric=globalThis.requestIdleCallback;typeof ric=="function"?(this._idleCallbackIsRic=true,this._idleCallbackHandle=ric.call(globalThis,()=>{this._idleCallbackHandle=null,this._tryKickoffDeferredDictionaryLoad("idle");},{timeout:2e3}),dictionaryLoadDevLog("scheduled requestIdleCallback (unified-defer)",{timeoutMs:2e3})):(this._idleCallbackIsRic=false,this._idleCallbackHandle=window.setTimeout(()=>{this._idleCallbackHandle=null,this._tryKickoffDeferredDictionaryLoad("idle");},0),dictionaryLoadDevLog("scheduled setTimeout(0) fallback (unified-defer)"));}_tryKickoffDeferredDictionaryLoad(source){if(!this.isConnected){return}if(this._dictionaryState==="loading"){return}this._dictionaryState!=="ready"&&(dictionaryLoadDevLog("deferred kickoff \u2192 _loadDictionary",{source,stateBefore:this._dictionaryState}),this._cancelDeferredDictionaryWaiters(),this._loadDictionary(`deferred:${source}`));}_attachDeferredFocusKickoff(el){if(this._dictionaryState==="ready")return;this._deferredFocusCleanup?.();let handler=()=>{this._tryKickoffDeferredDictionaryLoad("focusin");};el.addEventListener("focusin",handler,true),this._deferredFocusCleanup=()=>{el.removeEventListener("focusin",handler,true);};}_loadDictionary(trigger){let requestSeq=++this._dictionaryLoadSeq;this._dictionaryState="loading",this._customEngine=null;let hasGetDictionary=typeof this.getDictionary=="function";(hasGetDictionary?Promise.resolve(this.getDictionary()):this._importDefaultGoogleDict()).then(dict=>{if(requestSeq!==this._dictionaryLoadSeq)return;let engine=createPinyinEngine(dict);this._customEngine=engine,registerDefaultEngine(engine),this._dictionaryState="ready",dictionaryLoadDevLog("_loadDictionary ok",{trigger,requestSeq,dictKeyCount:Object.keys(dict).length});}).catch(()=>{requestSeq===this._dictionaryLoadSeq&&(this._customEngine=null,this._dictionaryState="error",dictionaryLoadDevLog("_loadDictionary error",{trigger,requestSeq}));}).finally(()=>{requestSeq===this._dictionaryLoadSeq&&(this._controller?.setOptions({getEngine:()=>this._resolvedEngine()}),this.requestUpdate());});}connectedCallback(){super.connectedCallback(),window.addEventListener("resize",this._onWinResize),window.addEventListener("scroll",this._onWinResize,true),queueMicrotask(()=>{this.isConnected&&(this._scheduleDeferredIdleCallback());});}disconnectedCallback(){super.disconnectedCallback(),this._cancelDeferredDictionaryWaiters(),this._cleanupNativeListeners?.(),this._cleanupNativeListeners=null,this._unsub?.(),this._unsub=null,this._controller=null,window.removeEventListener("resize",this._onWinResize),window.removeEventListener("scroll",this._onWinResize,true);}willUpdate(changedProperties){changedProperties.has("getDictionary")&&(this._cancelDeferredDictionaryWaiters(),this._loadDictionary("property:getDictionary"));}firstUpdated(){let el=this.inputRef.value;el&&(this._controller=new PinyinIMEController({getValue:()=>this.value,onValueChange:v2=>this._onValueChange(v2),getElement:()=>this.inputRef.value??null,getEngine:()=>this._resolvedEngine(),enabled:this.enabled,pageSize:this.pageSize}),this._unsub=this._controller.subscribe(()=>{this._syncPosition(),queueMicrotask(()=>this.requestUpdate());}),queueMicrotask(()=>this.requestUpdate()),this._cleanupNativeListeners=this._bindNativeListeners(el),this._dictionaryState!=="ready"&&this._attachDeferredFocusKickoff(el));}_bindNativeListeners(sourceEl){let onBeforeInput=e5=>{this._controller?.handleBeforeInput(e5);},onKeyDown=e5=>{this._controller?.handleKeyDown(e5);},onKeyUp=e5=>{this._controller?.handleKeyUp(e5);},onFocusLike=e5=>{this._forwardFocusEvent(e5);},onSelect=e5=>{this._forwardSimpleEvent(e5,"select",false);},onInvalid=e5=>{this._forwardSimpleEvent(e5,"invalid",true);};return sourceEl.addEventListener("beforeinput",onBeforeInput,true),sourceEl.addEventListener("keydown",onKeyDown,true),sourceEl.addEventListener("keyup",onKeyUp,true),sourceEl.addEventListener("focus",onFocusLike,true),sourceEl.addEventListener("blur",onFocusLike,true),sourceEl.addEventListener("focusin",onFocusLike,true),sourceEl.addEventListener("focusout",onFocusLike,true),sourceEl.addEventListener("select",onSelect,true),sourceEl.addEventListener("invalid",onInvalid,true),()=>{sourceEl.removeEventListener("beforeinput",onBeforeInput,true),sourceEl.removeEventListener("keydown",onKeyDown,true),sourceEl.removeEventListener("keyup",onKeyUp,true),sourceEl.removeEventListener("focus",onFocusLike,true),sourceEl.removeEventListener("blur",onFocusLike,true),sourceEl.removeEventListener("focusin",onFocusLike,true),sourceEl.removeEventListener("focusout",onFocusLike,true),sourceEl.removeEventListener("select",onSelect,true),sourceEl.removeEventListener("invalid",onInvalid,true);}}_forwardFocusEvent(e5){if(e5.target!==this.inputRef.value)return;(e5.type==="blur"||e5.type==="focusout")&&this._controller?.resetShiftGestureState();let forwarded=new FocusEvent(e5.type,{bubbles:true,composed:true,cancelable:e5.cancelable,relatedTarget:e5.relatedTarget});!this.dispatchEvent(forwarded)&&e5.cancelable&&e5.preventDefault();}_forwardSimpleEvent(e5,type,cancelable){if(e5.target!==this.inputRef.value)return;let forwarded=new Event(type,{bubbles:true,composed:true,cancelable});!this.dispatchEvent(forwarded)&&cancelable&&e5.cancelable&&e5.preventDefault();}_onValueChange(v2){this.value=v2;let el=this.inputRef.value;el&&(el.value=v2),this.dispatchEvent(new CustomEvent("change",{detail:{value:v2},bubbles:true,composed:true}));}updated(changedProperties){(changedProperties.has("enabled")||changedProperties.has("pageSize")||changedProperties.has("value"))&&this._controller?.setOptions({getValue:()=>this.value,onValueChange:v2=>this._onValueChange(v2),getElement:()=>this.inputRef.value??null,getEngine:()=>this._resolvedEngine(),enabled:this.enabled,pageSize:this.pageSize});let inputEl=this.inputRef.value;if(inputEl){inputEl.value!==this.value&&(inputEl.value=this.value);let passThrough=this._getPassThroughAttributes();for(let[name,value]of Object.entries(passThrough))inputEl.setAttribute(name,value);}}_onSelect(item){this._controller?.selectCandidate(item);}_onPageDelta(delta){this._controller?.addPage(delta);}_modeDescription(chineseMode){return chineseMode?"\u4E2D\u6587\u8F93\u5165\u6A21\u5F0F\uFF0C\u6309 Shift \u5207\u6362\u82F1\u6587":"\u82F1\u6587\u8F93\u5165\u6A21\u5F0F\uFF0C\u6309 Shift \u5207\u6362\u4E2D\u6587"}render(){let snap=this._controller?.getSnapshot(),show=snap?.hasActiveComposition&&this._position!=null&&snap.pinyinInput.length>0,chineseMode=snap?.chineseMode!==false,modeHint=this._modeDescription(chineseMode),field=this.editorType==="textarea"?T`<textarea
|
|
204
|
+
`;var defaultGoogleDictPromise=null;function getSharedDefaultGoogleDict(){return defaultGoogleDictPromise??=(async()=>{try{return (await import('pinyin-ime/dictionary/google_pinyin_dict')).dict}catch{throw new Error("Failed to import default google dictionary")}})()}function dictionaryLoadDevLog(...args){}var RESERVED_ATTRIBUTES=new Set(["value","editor-type","page-size","enabled","class","dictionary-load","popup-position"]),PinyinIMEEditor=class extends i3{static styles=[r(PINYIN_IME_STYLE_TEXT)];static properties={value:{type:String,converter:{fromAttribute(v2){return v2??""}}},editorType:{type:String,attribute:"editor-type",converter:{fromAttribute(value){return parseEditorTypeFromAttribute(value)}}},pageSize:{type:Number,attribute:"page-size",converter:{fromAttribute(value){return parsePageSizeFromAttribute(value)}}},enabled:{type:Boolean,converter:{fromAttribute(value){return parseEnabledFromAttribute(value)},toAttribute(value){return value?null:"false"}},reflect:true},popupPosition:{type:String,attribute:"popup-position",converter:{fromAttribute(value){return parsePopupPlacementFromAttribute(value)},toAttribute(value){return popupPlacementToAttribute(value)}}},getDictionary:{attribute:false}};inputRef=e4();_controller=null;_unsub=null;_cleanupNativeListeners=null;_customEngine=null;_dictionaryState="idle";_dictionaryLoadSeq=0;_position=null;_idleCallbackHandle=null;_idleCallbackIsRic=false;_deferredFocusCleanup=null;_onWinResize=()=>{this._syncPosition(),this.requestUpdate();};constructor(){super(),this.value="",this.editorType="input",this.enabled=true,this.pageSize=5,this.popupPosition="top";}focus(options){let target=this.inputRef.value;if(target){target.focus(options);return}super.focus(options);}blur(){let target=this.inputRef.value;if(target){target.blur();return}super.blur();}_resolvedEngine(){return this._customEngine}_syncPosition(){let el=this.inputRef.value,snap=this._controller?.getSnapshot();if(!el||!snap?.hasActiveComposition){this._position=null;return}let rect=el.getBoundingClientRect();this._position={top:rect.top,left:rect.left,width:rect.width,height:rect.height};}_popupStyle(position){return this.popupPosition==="bottom"?`top: ${position.top+position.height+2}px; left: ${position.left}px; width: ${position.width}px;`:this.popupPosition==="left"?`top: ${position.top}px; left: ${position.left-2}px; width: ${position.width}px; transform: translateX(-100%);`:this.popupPosition==="right"?`top: ${position.top}px; left: ${position.left+position.width+2}px; width: ${position.width}px;`:`top: ${position.top}px; left: ${position.left}px; width: ${position.width}px; transform: translateY(-100%) translateY(-2px);`}_getPassThroughAttributes(){let attrs={};for(let i5=0;i5<this.attributes.length;i5++){let a3=this.attributes[i5];RESERVED_ATTRIBUTES.has(a3.name)||(attrs[a3.name]=a3.value);}return attrs}_importDefaultGoogleDict(){return getSharedDefaultGoogleDict()}_cancelDeferredDictionaryWaiters(){this._idleCallbackHandle!==null&&(this._idleCallbackIsRic&&typeof cancelIdleCallback=="function"?cancelIdleCallback(this._idleCallbackHandle):clearTimeout(this._idleCallbackHandle),this._idleCallbackHandle=null),this._deferredFocusCleanup?.(),this._deferredFocusCleanup=null;}_scheduleDeferredIdleCallback(){if(this._dictionaryState==="loading"||this._dictionaryState==="ready"){dictionaryLoadDevLog("scheduleDeferredIdle skipped",{state:this._dictionaryState});return}if(this._idleCallbackHandle!==null){return}let ric=globalThis.requestIdleCallback;typeof ric=="function"?(this._idleCallbackIsRic=true,this._idleCallbackHandle=ric.call(globalThis,()=>{this._idleCallbackHandle=null,this._tryKickoffDeferredDictionaryLoad("idle");},{timeout:2e3}),dictionaryLoadDevLog("scheduled requestIdleCallback (unified-defer)",{timeoutMs:2e3})):(this._idleCallbackIsRic=false,this._idleCallbackHandle=window.setTimeout(()=>{this._idleCallbackHandle=null,this._tryKickoffDeferredDictionaryLoad("idle");},0),dictionaryLoadDevLog("scheduled setTimeout(0) fallback (unified-defer)"));}_tryKickoffDeferredDictionaryLoad(source){if(!this.isConnected){return}if(this._dictionaryState==="loading"){return}this._dictionaryState!=="ready"&&(dictionaryLoadDevLog("deferred kickoff \u2192 _loadDictionary",{source,stateBefore:this._dictionaryState}),this._cancelDeferredDictionaryWaiters(),this._loadDictionary(`deferred:${source}`));}_attachDeferredFocusKickoff(el){if(this._dictionaryState==="ready")return;this._deferredFocusCleanup?.();let handler=()=>{this._tryKickoffDeferredDictionaryLoad("focusin");};el.addEventListener("focusin",handler,true),this._deferredFocusCleanup=()=>{el.removeEventListener("focusin",handler,true);};}_loadDictionary(trigger){let requestSeq=++this._dictionaryLoadSeq;this._dictionaryState="loading",this._customEngine=null;let hasGetDictionary=typeof this.getDictionary=="function";(hasGetDictionary?Promise.resolve(this.getDictionary()):this._importDefaultGoogleDict()).then(dict=>{if(requestSeq!==this._dictionaryLoadSeq)return;let engine=createPinyinEngine(dict);this._customEngine=engine,registerDefaultEngine(engine),this._dictionaryState="ready",dictionaryLoadDevLog("_loadDictionary ok",{trigger,requestSeq,dictKeyCount:Object.keys(dict).length});}).catch(()=>{requestSeq===this._dictionaryLoadSeq&&(this._customEngine=null,this._dictionaryState="error",dictionaryLoadDevLog("_loadDictionary error",{trigger,requestSeq}));}).finally(()=>{requestSeq===this._dictionaryLoadSeq&&(this._controller?.setOptions({getEngine:()=>this._resolvedEngine()}),this.requestUpdate());});}connectedCallback(){super.connectedCallback(),window.addEventListener("resize",this._onWinResize),window.addEventListener("scroll",this._onWinResize,true),queueMicrotask(()=>{this.isConnected&&(this._scheduleDeferredIdleCallback());});}disconnectedCallback(){super.disconnectedCallback(),this._cancelDeferredDictionaryWaiters(),this._cleanupNativeListeners?.(),this._cleanupNativeListeners=null,this._unsub?.(),this._unsub=null,this._controller=null,window.removeEventListener("resize",this._onWinResize),window.removeEventListener("scroll",this._onWinResize,true);}willUpdate(changedProperties){changedProperties.has("getDictionary")&&(this._cancelDeferredDictionaryWaiters(),this._loadDictionary("property:getDictionary"));}firstUpdated(){let el=this.inputRef.value;el&&(this._controller=new PinyinIMEController({getValue:()=>this.value,onValueChange:v2=>this._onValueChange(v2),getElement:()=>this.inputRef.value??null,getEngine:()=>this._resolvedEngine(),enabled:this.enabled,pageSize:this.pageSize}),this._unsub=this._controller.subscribe(()=>{this._syncPosition(),queueMicrotask(()=>this.requestUpdate());}),queueMicrotask(()=>this.requestUpdate()),this._cleanupNativeListeners=this._bindNativeListeners(el),this._dictionaryState!=="ready"&&this._attachDeferredFocusKickoff(el));}_bindNativeListeners(sourceEl){let onBeforeInput=e5=>{this._controller?.handleBeforeInput(e5);},onKeyDown=e5=>{this._controller?.handleKeyDown(e5);},onKeyUp=e5=>{this._controller?.handleKeyUp(e5);},onFocusLike=e5=>{this._forwardFocusEvent(e5);},onSelect=e5=>{this._forwardSimpleEvent(e5,"select",false);},onInvalid=e5=>{this._forwardSimpleEvent(e5,"invalid",true);};return sourceEl.addEventListener("beforeinput",onBeforeInput,true),sourceEl.addEventListener("keydown",onKeyDown,true),sourceEl.addEventListener("keyup",onKeyUp,true),sourceEl.addEventListener("focus",onFocusLike,true),sourceEl.addEventListener("blur",onFocusLike,true),sourceEl.addEventListener("focusin",onFocusLike,true),sourceEl.addEventListener("focusout",onFocusLike,true),sourceEl.addEventListener("select",onSelect,true),sourceEl.addEventListener("invalid",onInvalid,true),()=>{sourceEl.removeEventListener("beforeinput",onBeforeInput,true),sourceEl.removeEventListener("keydown",onKeyDown,true),sourceEl.removeEventListener("keyup",onKeyUp,true),sourceEl.removeEventListener("focus",onFocusLike,true),sourceEl.removeEventListener("blur",onFocusLike,true),sourceEl.removeEventListener("focusin",onFocusLike,true),sourceEl.removeEventListener("focusout",onFocusLike,true),sourceEl.removeEventListener("select",onSelect,true),sourceEl.removeEventListener("invalid",onInvalid,true);}}_forwardFocusEvent(e5){if(e5.target!==this.inputRef.value)return;(e5.type==="blur"||e5.type==="focusout")&&this._controller?.resetShiftGestureState();let forwarded=new FocusEvent(e5.type,{bubbles:true,composed:true,cancelable:e5.cancelable,relatedTarget:e5.relatedTarget});!this.dispatchEvent(forwarded)&&e5.cancelable&&e5.preventDefault();}_forwardSimpleEvent(e5,type,cancelable){if(e5.target!==this.inputRef.value)return;let forwarded=new Event(type,{bubbles:true,composed:true,cancelable});!this.dispatchEvent(forwarded)&&cancelable&&e5.cancelable&&e5.preventDefault();}_onValueChange(v2){this.value=v2;let el=this.inputRef.value;el&&(el.value=v2),this.dispatchEvent(new CustomEvent("change",{detail:{value:v2},bubbles:true,composed:true}));}updated(changedProperties){(changedProperties.has("enabled")||changedProperties.has("pageSize")||changedProperties.has("value"))&&this._controller?.setOptions({getValue:()=>this.value,onValueChange:v2=>this._onValueChange(v2),getElement:()=>this.inputRef.value??null,getEngine:()=>this._resolvedEngine(),enabled:this.enabled,pageSize:this.pageSize});let inputEl=this.inputRef.value;if(inputEl){inputEl.value!==this.value&&(inputEl.value=this.value);let passThrough=this._getPassThroughAttributes();for(let[name,value]of Object.entries(passThrough))inputEl.setAttribute(name,value);}}_onSelect(item){this._controller?.selectCandidate(item);}_onPageDelta(delta){this._controller?.addPage(delta);}_modeDescription(chineseMode){return chineseMode?"\u4E2D\u6587\u8F93\u5165\u6A21\u5F0F\uFF0C\u6309 Shift \u5207\u6362\u82F1\u6587":"\u82F1\u6587\u8F93\u5165\u6A21\u5F0F\uFF0C\u6309 Shift \u5207\u6362\u4E2D\u6587"}render(){let snap=this._controller?.getSnapshot(),show=snap?.hasActiveComposition&&this._position!=null&&snap.pinyinInput.length>0,chineseMode=snap?.chineseMode!==false,modeHint=this.enabled?this._modeDescription(chineseMode):void 0,fieldModeBadgeClass=this.enabled?" pinyin-ime-field--with-mode-badge":"",field=this.editorType==="textarea"?T`<textarea
|
|
205
205
|
${n5(this.inputRef)}
|
|
206
|
-
class
|
|
206
|
+
class=${`pinyin-ime-textarea${fieldModeBadgeClass}`}
|
|
207
207
|
.value=${this.value}
|
|
208
208
|
aria-label=${modeHint}
|
|
209
209
|
title=${modeHint}
|
|
210
210
|
@input=${this._onNativeInput}
|
|
211
211
|
></textarea>`:T`<input
|
|
212
212
|
${n5(this.inputRef)}
|
|
213
|
-
class
|
|
213
|
+
class=${`pinyin-ime-input${fieldModeBadgeClass}`}
|
|
214
214
|
.value=${this.value}
|
|
215
215
|
aria-label=${modeHint}
|
|
216
216
|
title=${modeHint}
|
|
@@ -218,12 +218,12 @@ function joinClassNames(...parts){return parts.filter(Boolean).join(" ")}var _de
|
|
|
218
218
|
/>`;return T`
|
|
219
219
|
<div class="pinyin-ime-field-wrap">
|
|
220
220
|
${field}
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
221
|
+
${this.enabled?T`<span
|
|
222
|
+
part="mode-badge"
|
|
223
|
+
class="pinyin-ime-mode-badge"
|
|
224
|
+
aria-hidden="true"
|
|
225
|
+
>${chineseMode?"\u4E2D":"A"}</span
|
|
226
|
+
>`:A}
|
|
227
227
|
${show?this._renderPopup():A}
|
|
228
228
|
</div>
|
|
229
229
|
`}_onNativeInput(e5){let t5=e5.target;t5.value!==this.value&&this._onValueChange(t5.value);}_onPopupMouseDown(e5){e5.preventDefault();}_renderPopup(){let c5=this._controller,position=this._position;if(!c5||!position)return A;let loading=this._dictionaryState==="loading",{pinyinInput,pinyinCursorPosition,pinyinSelectionStart,pinyinSelectionEnd,candidates,displayCandidates,page,pageSize,highlightedCandidateIndex}=c5.getSnapshot(),totalPages=Math.ceil(candidates.length/pageSize)||1,hasPrev=page>0,hasNext=(page+1)*pageSize<candidates.length;return T`
|