/*! For license information please see main.js.LICENSE.txt */ (()=>{"use strict";var e={"../common/Settings.ts":(e,t,a)=>{a.r(t),a.d(t,{default:()=>SETTINGS});class SETTINGS{static init(e){this.MOD_NAME=e,String.prototype.localize||(String.prototype.localize=function(){return game.i18n.localize(this.valueOf())})}static register(e,t){game.settings.register(SETTINGS.MOD_NAME,e,t)}static registerMenu(e,t){game.settings.registerMenu(SETTINGS.MOD_NAME,e,t)}static get(e){return game.settings.get(SETTINGS.MOD_NAME,e)}static async set(e,t){return await game.settings.set(SETTINGS.MOD_NAME,e,t)}static default(e){return game.settings.settings.get(SETTINGS.MOD_NAME+"."+e).default}static typeOf(){return Object}}},"../common/libWrapperShared.ts":(e,t,a)=>{a.r(t),a.d(t,{default:()=>libWrapperShared});var r=a("../common/Settings.ts");class Registration{constructor(){this.nextId=0,this.wrappers=new Map}handler(e,t,...a){let r=t;for(const t of this.wrappers.values()){const a=r;r=(...r)=>t.call(e,a,...r)}return r.call(e,...a)}}class libWrapperShared{static register(e,t){let a=this.registrations.get(e);a||(a=new Registration,libWrapper.register(r.default.MOD_NAME,e,(function(e,...t){return a.handler(this,e,...t)}),"WRAPPER"),this.registrations.set(e,a));const i=a.nextId++;return a.wrappers.set(i,t),i}static unregister(e,t){const a=this.registrations.get(e);return!!a&&(a.wrappers.delete(t),0===a.wrappers.size&&(libWrapper.unregister(r.default.MOD_NAME,e,!1),this.registrations.delete(e)),!0)}}libWrapperShared.registrations=new Map},"./src/Util.ts":(e,t,a)=>{a.r(t),a.d(t,{default:()=>UTIL});class UTIL{static async requestReload(){await Dialog.confirm({title:"DF_CHAT_ENHANCE.ReloadGameTitle".localize(),content:"DF_CHAT_ENHANCE.ReloadGameContent".localize(),defaultYes:!0})&&window.location.reload()}static reloadChatLog(){ui.chat._lastId=null,ui.chat._state=Application.RENDER_STATES.NONE,ui.chat.render(!0)}}},"./src/archive/DFChatArchive.ts":(e,t,a)=>{a.r(t),a.d(t,{DFChatArchive:()=>DFChatArchive});var r=a("../common/Settings.ts");class ArchiveFolderMenu extends FormApplication{constructor(){super(...arguments),this.folder=r.default.get(DFChatArchive.PREF_FOLDER),this.source=r.default.get(DFChatArchive.PREF_FOLDER_SOURCE)}static get defaultOptions(){return mergeObject(FormApplication.defaultOptions,{width:400,height:125,resizable:!1,minimizable:!1,title:"DF_CHAT_ARCHIVE.Settings.ArchiveFolder_Name",template:"modules/df-chat-enhance/templates/archive-folder.hbs",submitOnClose:!1,submitOnChange:!1,closeOnSubmit:!0})}getData(e){return{path:this.folder}}async _renderInner(e){const t=await super._renderInner(e),a=t.find("input#dfce-ca-folder-path")[0];return t.find("label>button").on("click",(async e=>{e.preventDefault();const t=new FilePicker({title:"DF_CHAT_ARCHIVE.Settings.ArchiveFolder_Name",type:"folder",field:a,callback:async e=>{this.source=t.activeSource,this.folder=e},button:e.currentTarget});await t.browse(r.default.get(DFChatArchive.PREF_FOLDER))})),t}async _updateObject(){await r.default.set(DFChatArchive.PREF_FOLDER,this.folder),await r.default.set(DFChatArchive.PREF_FOLDER_SOURCE,this.source)}}class DFChatArchive{static get DATA_FOLDER(){return r.default.get(DFChatArchive.PREF_FOLDER_SOURCE)}static setUpdateListener(e){this._updateListener=e}static registerSettings(){r.default.register(this.PREF_LOGS,{scope:"world",config:!1,type:Object,default:[],onChange:()=>{null!=this._updateListener&&this._updateListener()}}),r.default.register(this.PREF_CID,{scope:"world",config:!1,type:Number,default:0}),r.default.registerMenu(this.PREF_FOLDER_MENU,{label:"DF_CHAT_ARCHIVE.Settings.ArchiveFolder_Name",hint:"DF_CHAT_ARCHIVE.Settings.ArchiveFolder_Hint",restricted:!0,type:ArchiveFolderMenu}),r.default.register(this.PREF_FOLDER,{scope:"world",config:!1,type:String,default:`worlds/${game.world.id}/chat-archive`,onChange:async()=>{await this.createArchiveFolderIfMissing(),null!=this._updateListener&&this._updateListener()}}),r.default.register(this.PREF_FOLDER_SOURCE,{scope:"world",config:!1,type:String,default:"data"}),this.createArchiveFolderIfMissing()}static async createArchiveFolderIfMissing(){const e=r.default.get(this.PREF_FOLDER);await FilePicker.browse(this.DATA_FOLDER,e).catch((async t=>{if(!await FilePicker.createDirectory(this.DATA_FOLDER,e,{}))throw new Error("Could not access the archive folder: "+e)}))}static getLogs(){return r.default.get(this.PREF_LOGS)}static getArchive(e){return this.getLogs().find((t=>t.id==e))}static exists(e){return!!this.getLogs().find((t=>t.id==e))}static async _generateChatArchiveFile(e,t,a,i){const o=r.default.get(this.PREF_FOLDER),s=t.replace(/[^ a-z0-9-_()[\]<>]/gi,"_"),n=encodeURI(`${e}_${s}.json`),l=new File([JSON.stringify(a,null,"")],n,{type:"application/json"}),c=await FilePicker.upload(this.DATA_FOLDER,o,l);if(!c.path)throw console.error(`Could not create archive ${n}\nReason: ${c}`),new Error("Could not upload the archive to server: "+n);return{id:e,name:t,visible:i,filepath:c.path,filename:n}}static async createChatArchive(e,t,a){const i=r.default.get(this.PREF_CID)+1;r.default.set(this.PREF_CID,i);const o=await this._generateChatArchiveFile(i,e,t,a),s=r.default.get(this.PREF_LOGS);return s.push(o),await r.default.set(this.PREF_LOGS,s),null!=this._updateListener&&this._updateListener(),o}static async getArchiveContents(e){const t=await fetch(e.filepath),a=await t.json().catch((t=>console.error(`Failed to read JSON for archive ${e.filepath}\n${t}`)));if(t.ok)return a;throw new Error("Could not access the archive from server side: "+e.filepath)}static async updateChatArchive(e,t){if(!this.getLogs().find((t=>t.id==e.id)))throw new Error("Could not locate an archive for the given ID: "+e.id.toString());if(t){const a=r.default.get(this.PREF_FOLDER),i=new File([JSON.stringify(t)],e.filename,{type:"application/json"});if(!(await FilePicker.upload(this.DATA_FOLDER,a,i,{})).path)throw new Error("Could not upload the archive to server side: "+e.id.toString())}const a=this.getLogs(),i=a.findIndex((t=>t.id===e.id));return i<0||(a[i]=e,await r.default.set(DFChatArchive.PREF_LOGS,a)),e}static async deleteAll(){const e=r.default.get(this.PREF_FOLDER),t=r.default.get(this.PREF_LOGS);await Promise.all(t.map((t=>{const a=new File([""],t.filename,{type:"application/json"});return FilePicker.upload(this.DATA_FOLDER,e,a,{})}))),await r.default.set(this.PREF_LOGS,[]),null!=this._updateListener&&this._updateListener()}static async deleteChatArchive(e){const t=r.default.get(this.PREF_FOLDER),a=r.default.get(this.PREF_LOGS),i=a.findIndex((t=>t.id===e));if(i<0)return void console.error(`Could not find entry for ID#${e}`);const o=a[i],s=new File([""],o.filename,{type:"application/json"});await FilePicker.upload(this.DATA_FOLDER,t,s,{}),a.splice(i,1),await r.default.set(this.PREF_LOGS,a),null!=this._updateListener&&this._updateListener()}}DFChatArchive.PREF_LOGS="logs",DFChatArchive.PREF_CID="currentId",DFChatArchive.PREF_FOLDER="archiveFolder",DFChatArchive.PREF_FOLDER_SOURCE="archiveFolderSource",DFChatArchive.PREF_FOLDER_MENU="archiveFolderMenu",DFChatArchive._updateListener=null},"./src/archive/DFChatArchiveManager.ts":(e,t,a)=>{a.r(t),a.d(t,{default:()=>DFChatArchiveManager});var r=a("../common/Settings.ts"),i=a("./src/archive/DFChatArchive.ts"),o=a("./src/archive/DFChatArchiveViewer.ts");class DFChatArchiveManager extends Application{static get defaultOptions(){return mergeObject(Application.defaultOptions,{template:"modules/df-chat-enhance/templates/archive-manager.hbs",resizable:!0,minimizable:!0,width:300,height:500,title:"DF_CHAT_ARCHIVE.ArchiveManager_Title".localize()})}getData(e){const t=super.getData(e);let a=i.DFChatArchive.getLogs();game.user.isGM||(a=a.filter((e=>e.visible))),a=a.sort(((e,t)=>e.name.localeCompare(t.name)));const o=r.default.get(DFChatArchiveManager.PREF_REVERSE_SORT);return mergeObject(t,{messages:o?a.reverse():a,isGM:game.user.isGM,reverseSort:o}),t}_subscribeView(e){e.on("click",(function(){const e=parseInt($(this).attr("data-id"));if(isNaN(e)||!i.DFChatArchive.exists(e))throw ui.notifications.error("DF_CHAT_ARCHIVE.ArchiveManager_ErrorBadId".localize()),Error(`Invalid id for Chat Archive: '${$(this).attr("data-id")}'`);DFChatArchiveManager.chatViewers.has(e)?DFChatArchiveManager.chatViewers.get(e).bringToTop():(DFChatArchiveManager.chatViewers.set(e,new o.default(i.DFChatArchive.getArchive(e),(e=>{DFChatArchiveManager.chatViewers.delete(e.archive.id)}))),DFChatArchiveManager.chatViewers.get(e).render(!0))}))}_subscribeDelete(e){e.on("click",(async function(){const e=parseInt($(this).attr("data-id"));if(isNaN(e)||!i.DFChatArchive.exists(e))throw ui.notifications.error("DF_CHAT_ARCHIVE.ArchiveManager_ErrorBadId".localize()),Error(`Invalid id for Chat Archive: '${$(this).attr("data-id")}'`);const t=i.DFChatArchive.getArchive(e);await Dialog.confirm({title:"DF_CHAT_ARCHIVE.ArchiveManager_ConfirmDeleteArchiveTitle".localize(),content:"DF_CHAT_ARCHIVE.ArchiveManager_ConfirmDeleteArchiveContent".localize().replace("{name}",t.name),defaultYes:!1,yes:async()=>await i.DFChatArchive.deleteChatArchive(e)})}))}activateListeners(e){i.DFChatArchive.setUpdateListener(this._archiveChanged.bind(this)),i.DFChatArchive.getLogs().length>0&&e.find("p.dfca-no-items").hide(),e.find('a[data-type="view"]').each(((e,t)=>{this._subscribeView($(t))})),e.find('a[data-type="delete"]').each(((e,t)=>{this._subscribeDelete($(t))})),e.find("#dfca-delete-all").on("click",(async function(){await Dialog.confirm({title:"DF_CHAT_ARCHIVE.ArchiveManager_ConfirmDeleteAllTitle".localize(),content:"DF_CHAT_ARCHIVE.ArchiveManager_ConfirmDeleteAllMessage1".localize(),defaultYes:!1,yes:async()=>{await Dialog.confirm({title:"DF_CHAT_ARCHIVE.ArchiveManager_ConfirmDeleteAllTitle".localize(),content:"DF_CHAT_ARCHIVE.ArchiveManager_ConfirmDeleteAllMessage2".localize(),defaultYes:!1,yes:async()=>{await i.DFChatArchive.deleteAll(),ui.notifications.info("DF_CHAT_ARCHIVE.ArchiveManager_ConfirmDeleteAllComplete".localize())}})}})}));const t=e.find("#dfca-sort-asc"),a=e.find("#dfca-sort-dsc");t.on("click",(async()=>{await r.default.set(DFChatArchiveManager.PREF_REVERSE_SORT,!0),t.hide(),a.show(),this.render()})),a.on("click",(async()=>{await r.default.set(DFChatArchiveManager.PREF_REVERSE_SORT,!1),a.hide(),t.show(),this.render()}))}close(e){return i.DFChatArchive.setUpdateListener(null),super.close(e)}async _archiveChanged(){let e=i.DFChatArchive.getLogs();game.user.isGM||(e=e.filter((e=>e.visible)));const t=this.element.find("#dfca-archives");t.empty();for(const a of e){const e=!0===a.visible?``:"",r=$(`\n\t\t
  • \n\t\t\t
    \n\t\t\t\t\n\t\t\t\t\t${a.name}\n\t\t\t\t\n\t\t\t\t${e}\n\t\t\t\t\n\t\t\t
    \n\t\t
  • `);this._subscribeView(r.find('a[data-type="view"]')),this._subscribeDelete(r.find('a[data-type="delete"]')),t.append(r)}0==t[0].children.length?this.element.find("p.dfca-no-items").show():this.element.find("p.dfca-no-items").hide()}}DFChatArchiveManager.PREF_REVERSE_SORT="dfca-manager-reverseSort",DFChatArchiveManager.chatViewers=new Map},"./src/archive/DFChatArchiveNew.ts":(e,t,a)=>{a.r(t),a.d(t,{default:()=>DFChatArchiveNew});var r=a("./src/archive/DFChatArchive.ts"),i=a("../common/Settings.ts");class DFChatArchiveNew extends FormApplication{static get defaultOptions(){return mergeObject(FormApplication.defaultOptions,{template:"modules/df-chat-enhance/templates/archive-new.hbs",resizable:!1,minimizable:!1,title:"DF_CHAT_ARCHIVE.ArchiveNew_Title".localize()})}static registerSettings(){i.default.register(DFChatArchiveNew.PREF_DELETE,{config:!1,scope:"world",type:Boolean,default:!0})}getData(e){return mergeObject(super.getData(e),{shouldDelete:i.default.get(DFChatArchiveNew.PREF_DELETE)})}async _updateObject(e,t){i.default.set(DFChatArchiveNew.PREF_DELETE,t.delete);const a=t.name;if(!a)throw ui.notifications.warn("DF_CHAT_ARCHIVE.ArchiveNew_ErrorNameMissing".localize()),Error("DF_CHAT_ARCHIVE.ArchiveNew_ErrorNameMissing".localize());let o=[...ui.chat.collection.values()];if("date"===t["date-or-all"]){const e=new Date(t.from).getTime(),a=new Date(t.to).getTime();if(isNaN(e)||isNaN(a))throw ui.notifications.warn("DF_CHAT_ARCHIVE.ArchiveNew_ErrorDatesMissing".localize()),Error('Missing "from" and/or "to" dates');o=o.filter((t=>t.data.timestamp>=e&&t.data.timestamp<=a))}ui.notifications.info("DF_CHAT_ARCHIVE.ArchiveNew_NoticeSuccess".localize().replace("{0}",a));try{await r.DFChatArchive.createChatArchive(a,o,t.visible)}catch(e){return}t.delete&&game.messages.flush()}_renderInner(e){return super._renderInner(e).then((e=>{const t=e.find("#dfca-from"),a=e.find("#dfca-to");return e.find("#dfca-all").on("change",(()=>{t.prop("disabled",!0),a.prop("disabled",!0),this._recalculateDimensions()})),e.find("#dfca-date").on("change",(()=>{t.prop("disabled",!1),a.prop("disabled",!1),this._recalculateDimensions()})),e}))}}DFChatArchiveNew.PREF_DELETE="new-should-delete",DFChatArchiveNew.PREF_HIDE_EXPORT="hide-export"},"./src/archive/DFChatArchiveViewer.ts":(e,t,a)=>{a.r(t),a.d(t,{default:()=>DFChatArchiveViewer});var r=a("./src/archive/DFChatArchive.ts");class DFChatArchiveViewer extends Application{constructor(e,t){super(),this.archive=e,this.onCloseCallBack=t}static get defaultOptions(){return mergeObject(Application.defaultOptions,{template:"modules/df-chat-enhance/templates/archive-viewer.hbs",width:300,height:500,resizable:!0,title:"DF_CHAT_ARCHIVE.ArchiveViewer_Title",classes:["df-chat-log-window"]})}getData(e={}){var t;return super.getData(e),{name:this.archive.name,isGM:game.user.isGM,visible:null!==(t=this.archive.visible)&&void 0!==t&&t,logId:"df-chat-log-"+this.archive.id}}static toBinary(e){const t=new Uint16Array(e.length);for(let a=0;a{e.find("#visible-df-chat-log-"+this.archive.id).on("change",(async e=>{this.archive.visible=e.target.checked,await r.DFChatArchive.updateChatArchive(this.archive)})),e.find("#edit").on("click",(async()=>{setTimeout((async()=>{const e=new Dialog({title:"DF_CHAT_ARCHIVE.ArchiveViewer_NameEdit_Title".localize(),content:``,buttons:{save:{icon:'',label:"DF_CHAT_ARCHIVE.ArchiveViewer_NameEdit_Save".localize(),callback:async t=>{this.archive.name=$(t).find("#name").val(),await e.close(),await r.DFChatArchive.updateChatArchive(this.archive),await this.render(!1)}},close:{icon:'',label:"DF_CHAT_ARCHIVE.ArchiveViewer_NameEdit_Cancel".localize(),callback:async()=>{await e.close()}}},default:"save"});e.render(!0)}),1)})),e.find("#print").on("click",(async()=>{const t=e.find("#df-chat-log").clone();t.addClass("df-chat-print"),$("body").hide(),$("html").addClass("df-chat-print"),$("html").append(t),window.print(),t.remove(),$("html").removeClass("df-chat-print"),$("body").show()})),e.find("#merge").on("click",(async()=>{if(1==r.DFChatArchive.getLogs().length)return void ui.notifications.info("DF_CHAT_ARCHIVE.ArchiveViewer_Merge_OnlyOneArchive".localize());const e=new Dialog({title:"DF_CHAT_ARCHIVE.ArchiveViewer_Merge_Title".localize(),default:"merge",content:await renderTemplate("modules/df-chat-enhance/templates/archive-merge.hbs",{id:this.archive.id,name:this.archive.name,archives:r.DFChatArchive.getLogs().filter((e=>e.id!=this.archive.id))}),buttons:{cancel:{icon:'',label:"DF_CHAT_ARCHIVE.ArchiveViewer_Merge_Cancel".localize(),callback:async()=>await e.close()},merge:{icon:'',label:"DF_CHAT_ARCHIVE.ArchiveViewer_Merge_Merge".localize(),callback:async e=>{const t=$(e).find("#archive").val();if(isNaN(parseInt(t)))return;const a=parseInt(t),i=r.DFChatArchive.getLogs().find((e=>e.id==a)),o=await r.DFChatArchive.getArchiveContents(this.archive),s=await r.DFChatArchive.getArchiveContents(i),n=o.concat(s).sort(((e,t)=>e.timestamp-t.timestamp));await r.DFChatArchive.updateChatArchive(this.archive,n),this.render(!0),$(e).find("#delete-"+this.archive.id)[0].checked&&await r.DFChatArchive.deleteChatArchive(a)}}}});await e.render(!0)})),e.find("#html").on("click",(()=>{const t=$("
    ").append(e.find("#df-chat-log").clone()).html(),a=document.createElement("a");a.download=encodeURI(this.archive.name)+".html",a.href="data:text/html,"+encodeURIComponent(t),a.click()}));const t=e.find("#df-chat-log"),a=[];this.messages=(await r.DFChatArchive.getArchiveContents(this.archive)).filter((e=>game.user.isGM||e.user===game.userId||e.type!==CONST.CHAT_MESSAGE_TYPES.WHISPER||e.whisper.some((e=>e===game.userId))));const i=[],o=e.find("#dfal-save-changes");for(const e of this.messages){const t=e instanceof ChatMessage?e:new ChatMessage(e);try{const e=await t.getHTML();1==this.messages.length&&e.find("a.message-delete").hide(),e.find("a.message-delete").on("click",(e=>{var t,a,r;const s=$(null===(r=null===(a=null===(t=e.target.parentElement)||void 0===t?void 0:t.parentElement)||void 0===a?void 0:a.parentElement)||void 0===r?void 0:r.parentElement),n=$(e.target);s.hasClass("dfal-deleted")?(s.removeClass("dfal-deleted"),n.removeClass("fa-redo-alt"),n.addClass("fa-trash"),i.splice(i.findIndex((e=>e===s.attr("data-message-id"))),1)):(s.addClass("dfal-deleted"),n.removeClass("fa-trash"),n.addClass("fa-redo-alt"),i.push(s.attr("data-message-id"))),i.length>0?o.show():o.hide()})),a.push(e)}catch(e){console.error(`Chat message ${t.id} failed to render.\n${e})`)}}return t.prepend(a),o.hide(),o.on("click",(async()=>{i.length!==this.messages.length?Dialog.confirm({title:"DF_CHAT_ARCHIVE.ArchiveViewer_DeleteTitle".localize(),content:"DF_CHAT_ARCHIVE.ArchiveViewer_DeleteContent".localize(),defaultYes:!1,yes:async()=>{for(const t of i){const a=e.find(`li[data-message-id="${t}"]`);a.hide(500,(()=>a.remove()))}this.messages=this.messages.filter((e=>!i.includes(e._id))),await r.DFChatArchive.updateChatArchive(this.archive,this.messages)}}):ui.notifications.warn("DF_CHAT_ARCHIVE.ArchiveViewer_Error_Delete_All".localize())})),e}))}close(e){return this.onCloseCallBack(this),super.close(e)}}},"./src/archive/df-chat-archive.ts":(e,t,a)=>{a.r(t),a.d(t,{init:()=>init});var r=a("./src/archive/DFChatArchiveNew.ts"),i=a("./src/archive/DFChatArchiveManager.ts"),o=a("./src/archive/DFChatArchive.ts"),s=a("../common/Settings.ts");function init(){let e=null,t=null;o.DFChatArchive.registerSettings(),r.default.registerSettings(),s.default.register(r.default.PREF_HIDE_EXPORT,{name:"DF_CHAT_ARCHIVE.Settings.HideExport",scope:"world",type:Boolean,default:!1,config:!0,onChange:e=>{e?$("#chat-controls .export-log").hide():$("#chat-controls .export-log").show()}}),s.default.register(i.default.PREF_REVERSE_SORT,{scope:"world",type:Boolean,default:!1,config:!1}),Hooks.on("renderChatLog",(function(t,a){const i=$(`\n\t\t`);i.on("click",(()=>{null==e?(e=new r.default({}),e.render(!0)):e.bringToTop()})),a.find(".control-buttons").prepend(i).attr("style","flex:0 0 auto;"),s.default.get(r.default.PREF_HIDE_EXPORT)&&a.find(".control-buttons .export-log").hide()})),Hooks.on("renderSettings",(function(e,a){const r=$(`
    \n\t

    ${"DF_CHAT_ARCHIVE.ChatEnhanceSettingGroup".localize()}

    \n\t\n
    `);r.on("click",(()=>{null!=t&&[Application.RENDER_STATES.RENDERED,Application.RENDER_STATES.RENDERING].includes(t._state)?t.bringToTop():(t=new i.default,t.render(!0))})),a.find("#settings-game").append(r)})),Hooks.on("closeDFChatArchiveNew",(()=>{e=null})),Hooks.on("closeDFChatArchiveManager",(()=>{e=null})),Hooks.on("renderDFChatArchiveNew",(function(e,t){t.find('input[type="text"]')[0].focus()}))}},"./src/chat-time/chat-time.ts":(e,t,a)=>{a.r(t),a.d(t,{default:()=>ChatTime});var r=a("../common/Settings.ts"),i=a("./src/Util.ts");class ChatTime{static get enabled(){return r.default.get(this.PREF_ENABLED)}static get simpleCalendarActive(){var e;return!!(null===(e=game.modules.get("foundryvtt-simple-calendar"))||void 0===e?void 0:e.active)}static ready(){!this.simpleCalendarActive&&game.user.isGM&&this.enabled&&ui.notifications.warn("DF_CHAT_TIME.ErrorSimpleCalendarMissing",{permanent:!0,localize:!0})}static init(){r.default.register(this.PREF_ENABLED,{scope:"world",type:Boolean,name:"DF_CHAT_TIME.EnabledName",hint:"DF_CHAT_TIME.EnabledHint",default:!1,config:!0,onChange:i.default.reloadChatLog}),r.default.register(this.PREF_FORMAT,{scope:"world",type:String,name:"DF_CHAT_TIME.FormatName",hint:"DF_CHAT_TIME.FormatHint",default:"YYYY, MMM DD, HH:mm",config:this.simpleCalendarActive,onChange:i.default.reloadChatLog}),libWrapper.register(r.default.MOD_NAME,"ChatMessage.implementation.create",((e,t,a)=>{var i;return t.flags=null!==(i=t.flags)&&void 0!==i?i:{},t.flags[r.default.MOD_NAME]={},t.flags[r.default.MOD_NAME][this.FLAG_CHAT_TIME]=game.time.worldTime,e(t,a)}),"WRAPPER"),Hooks.on("renderChatMessage",((e,t,a)=>{if(!this.simpleCalendarActive||!this.enabled)return;const i=e.getFlag(r.default.MOD_NAME,this.FLAG_CHAT_TIME);if(void 0===i)return;const o=t.find(".message-timestamp"),s=$(``);o.after(s),o.hide()}))}}ChatTime.PREF_ENABLED="ChatTime.UseSimpleCalender",ChatTime.PREF_FORMAT="ChatTime.SimpleCalendarFormat",ChatTime.FLAG_CHAT_TIME="ChatTime.WorldTime"},"./src/edit/DFChatEditor.ts":(e,t,a)=>{a.r(t),a.d(t,{default:()=>DFChatEditor});var r=a("../common/Settings.ts"),i=a("./src/edit/df-chat-edit.ts");class DFChatEditor extends FormApplication{constructor(e){super({}),this.chatMessage=e}static get defaultOptions(){return mergeObject(FormApplication.defaultOptions,{closeOnSubmit:!0,editable:!0,resizable:!0,width:400,popOut:!0,title:"DF_CHAT_EDIT.Editor_Title",template:"modules/df-chat-enhance/templates/chat-edit.hbs"})}getData(e){const t=Object.keys(CONFIG.Actor.typeLabels).map((e=>({type:e,label:CONFIG.Actor.typeLabels[e],actors:[]})));for(const e of t)e.actors=game.scenes.viewed.tokens.contents.filter((t=>t.actor.type===e.type)).map((e=>({id:"token-"+e.id,name:e.name})));let a="";return this.chatMessage.user&&(a="user-"+this.chatMessage.user),this.chatMessage.speaker.token&&(a="token-"+this.chatMessage.speaker.token),mergeObject(e,{selected:a,players:game.users.map((e=>({id:"user-"+e.id,name:e.name}))),actorGroups:t.filter((e=>e.actors.length>0)),messageText:this.chatMessage.content.replace(/< *br *\/?>/gm,"\n").replace(/

    .+/,"")})}activateListeners(e){super.activateListeners(e),e.find("#cancel").on("click",(async()=>await this.close()))}async _updateObject(e,t){let a,o,s=t.content;s=r.default.get(DFChatEditor.PREF_MARKDOWN)?DFChatEditor.processMarkdown(s)[1]:s.replace(/\r?\n/gm,"
    "),r.default.get(i.default.PREF_SHOW_EDITED)&&s.search(/

    /)<0&&(s+=`

    ${"DF_CHAT_EDIT.EditedFlag".localize()}

    `),t.speaker.startsWith("user-")?(o=game.users.get(t.speaker.substring("user-".length)).id,a=ChatMessage._getSpeakerFromUser({user:o})):a=ChatMessage.getSpeaker({token:game.scenes.viewed.tokens.get(t.speaker.substring("token-".length))}),void 0===a.alias&&(a.alias=null),this.chatMessage.update({content:s,speaker:a,user:o})}close(e){return delete this.chatMessage.chatEditor,super.close(e)}static processMarkdown(e){const t=e;(e=marked.parse(e,{headerIds:!1,breaks:!0}).trimEnd()).startsWith("

    ")&&(e=e.substr(3)),e.endsWith("

    ")&&(e=e.substr(0,e.length-4));const a=/(<\/?[ a-z]+>)\n(<\/?[ a-z]+>?)/;for(;a.test(e);)e=e.replace(a,"$1$2");return[t,e]}}DFChatEditor.PREF_MARKDOWN="edit-markdown"},"./src/edit/df-chat-edit.ts":(e,t,a)=>{a.r(t),a.d(t,{default:()=>DFChatEdit});var r=a("../common/Settings.ts"),i=a("./src/edit/DFChatEditor.ts");const o="edit-allowed",s="gm-edit-all",n="edit-ignore-html";class DFChatEdit{static ready(){r.default.register(i.default.PREF_MARKDOWN,{name:"DF_CHAT_EDIT.Settings_MarkdownName",hint:"DF_CHAT_EDIT.Settings_MarkdownHint",type:Boolean,default:!0,config:!0,scope:"world"}),r.default.register(o,{name:"DF_CHAT_EDIT.Settings_AllowEditName",hint:"DF_CHAT_EDIT.Settings_AllowEditHint",type:Boolean,default:!0,scope:"world",config:!0}),r.default.register(s,{name:"DF_CHAT_EDIT.Settings_GMEditAllName",hint:"DF_CHAT_EDIT.Settings_GMEditAllHint",type:Boolean,default:!1,config:!0,scope:"world"}),r.default.register(n,{name:"DF_CHAT_EDIT.Settings_IgnoreHtmlName",hint:"DF_CHAT_EDIT.Settings_IgnoreHtmlHint",type:Boolean,default:!1,config:!0,scope:"world"}),r.default.register(this.PREF_SHOW_EDITED,{name:"DF_CHAT_EDIT.Settings_ShowEditedLabelName",hint:"DF_CHAT_EDIT.Settings_ShowEditedLabelHint",type:Boolean,default:!0,config:!0,scope:"world"}),libWrapper.register(r.default.MOD_NAME,"ChatLog.prototype._onChatKeyDown",((e,...t)=>{const a=t[0];if("ArrowUp"===a.code&&a.ctrlKey){a.preventDefault();let e=[...ui.chat.collection.values()];e=e.sort(((e,t)=>t.timestamp-e.timestamp));const t=e.find((e=>e.user===game.user.id));if(!t)return;DFChatEdit.editChatMessage.bind(t)()}else e(...t)}),"MIXED"),libWrapper.register(r.default.MOD_NAME,"ChatLog.prototype.processMessage",(function(e,t){let a=null;if(r.default.get(i.default.PREF_MARKDOWN))if(t.trim().startsWith("/")){const e=t.split(" ")[0].trim();switch(e){case"/ooc":case"/ic":case"/emote":case"/whisper":case"/w":[a,t]=i.default.processMarkdown(t.substr(e.length)),a=`${e} ${a.trimStart()}`,t=`${e} ${t.trimStart()}`}}else[a,t]=i.default.processMarkdown(t);const o=e(t);return a&&(this._sentMessages.splice(0,1),this._sentMessages.unshift(a)),o}),"WRAPPER")}static appendChatContextMenuOptions(e){e.push({name:"DF_CHAT_EDIT.ContextOption",icon:'',condition:e=>{const t=ui.chat.collection.get($(e).attr("data-message-id"));return this.processChatMessage(t)},callback:e=>{const t=ui.chat.collection.get($(e).attr("data-message-id"));return DFChatEdit.editChatMessage.bind(t)(),{}}})}static async editChatMessage(){r.default.get(o)?(this.chatEditor?this.chatEditor.bringToTop():(this.chatEditor=new i.default(this),await this.chatEditor._render(!0)),this.chatEditor.element.find("textarea").focus()):ui.notifications.warn("DF_CHAT_EDIT.Error_NoPermission".localize())}static isHTML(e){const t=(new DOMParser).parseFromString(e,"text/html");return Array.from(t.body.childNodes).some((e=>e instanceof HTMLElement&&!e.classList.contains("df-edited")&&!(e instanceof HTMLBRElement)&&1===e.nodeType))}static processChatMessage(e){return!!ui.chat.collection.has(e.id)&&(!(!r.default.get(o)||e.isRoll||!(e.user.id===game.userId||game.user.isGM&&r.default.get(s)))&&(!r.default.get(n)||!DFChatEdit.isHTML(e.content)))}}DFChatEdit.PREF_SHOW_EDITED="DFChatEdit.ShowEditedLable"},"./src/font-size/font-size.ts":(e,t,a)=>{a.r(t),a.d(t,{default:()=>FontSizePatch});var r=a("../common/Settings.ts");class FontSizePatch{static init(){r.default.register(this.PREF_SIZE,{name:"DF_CHAT_FONT_SIZE.FontSizeName".localize(),hint:"DF_CHAT_FONT_SIZE.FontSizeHint".localize(),config:!0,type:Number,scope:"client",range:{min:10,max:30,step:.5},default:14,onChange:e=>this.updateFontSize(e)}),this.updateFontSize(r.default.get(this.PREF_SIZE))}static updateFontSize(e){document.querySelector(":root").style.setProperty("--dfce-chat-font-size",e.toString()+"px")}}FontSizePatch.PREF_SIZE="FontSizePatch.FontSize"},"./src/logger/DFAdventureLogConfig.ts":(e,t,a)=>{a.r(t),a.d(t,{default:()=>DFAdventureLogConfig});var r=a("../common/Settings.ts"),i=a("./src/logger/DFAdventureLogProcessor.ts");class DFAdventureLogConfig extends FormApplication{static get defaultOptions(){return mergeObject(FormApplication.defaultOptions,{template:"modules/df-chat-enhance/templates/log-config.hbs",resizable:!1,minimizable:!1,title:"DF_CHAT_LOG.Config_Title".localize()})}static setupSettings(){r.default.register(DFAdventureLogConfig.PREF_JOURNAL,{scope:"world",type:String,default:"",config:!1}),r.default.register(DFAdventureLogConfig.PREF_JOURNAL_GM,{scope:"world",type:String,default:"",config:!1}),r.default.registerMenu(DFAdventureLogConfig.PREF_CONFIG,{restricted:!0,type:DFAdventureLogConfig,label:"DF_CHAT_LOG.Config_Title",icon:"fas fa-edit"})}getData(e){var t,a;const i=super.getData(e),o=game.journal.contents.filter((e=>e.pages.contents.some((e=>"text"===e.type)))).map((e=>e.id)),s=null===(t=r.default.get(DFAdventureLogConfig.PREF_JOURNAL))||void 0===t?void 0:t.split("."),n=null===(a=r.default.get(DFAdventureLogConfig.PREF_JOURNAL_GM))||void 0===a?void 0:a.split(".");let l=[],c=[],d=[],g=[];for(const e of o)l.push({id:e,name:game.journal.get(e).name,selected:s&&e===s[0]}),s&&e===s[0]&&(c=game.journal.get(e).pages.contents.map((t=>({id:e+"."+t.id,name:t.name,selected:t.id===s[1]})))),d.push({id:e,name:game.journal.get(e).name,selected:n&&e===n[0]}),n&&e===n[0]&&(g=game.journal.get(e).pages.contents.map((t=>({id:e+"."+t.id,name:t.name,selected:t.id===n[1]}))));return l=l.sort(((e,t)=>e.name.localeCompare(t.name))),d=d.sort(((e,t)=>e.name.localeCompare(t.name))),mergeObject(i,{logJournals:l,logJournalPages:c,gmlogJournals:d,gmlogJournalPages:g}),i}fillPageList(e,t){t.children().remove();const a=game.journal.get(e);if(a)for(const r of a.pages.contents.filter((e=>"text"==e.type)))t.append(``)}activateListeners(e){e.find("#dfal-journal").on("change",(t=>{const a=t.currentTarget.value,r=e.find("#dfal-journal-page");this.fillPageList(a,r)})),e.find("#dfal-journal-gm").on("change",(t=>{const a=t.currentTarget.value,r=e.find("#dfal-journal-gm-page");this.fillPageList(a,r)}))}async _updateObject(e,t){const a=t["dfal-journal-page"],i=t["dfal-journal-gm-page"],o=t["dfal-clear"],s=t["dfal-clear-gm"];r.default.set(DFAdventureLogConfig.PREF_JOURNAL,a),r.default.set(DFAdventureLogConfig.PREF_JOURNAL_GM,i),await DFAdventureLogConfig.initializeJournal(a,o,!1,!1),await DFAdventureLogConfig.initializeJournal(i,s,!0,!1)}static async initializeJournal(e,t,a,r){const o=null==e?void 0:e.split(".");if(!o||o.length<2||!game.journal.has(o[0]))return;const s=game.journal.get(o[0]).pages.get(o[1]);(t||null===s.text.content)&&(s.text.content="");0==$(s.text.content).find('article[class="df-adventure-log"]').length?await s.update({"text.content":s.text.content+`\n\t\t\t
    \n\t\t\t\t

    ${game.i18n.localize(a?"DF_CHAT_LOG.GMLog_Header":r?"DF_CHAT_LOG.PLog_Header":"DF_CHAT_LOG.Log_Header")}

    \n\t\t\t\t
    \n\t\t\t\t
    \n\t\t\t
    \n\t\t\t`}):await i.default.resortLog()}}DFAdventureLogConfig.PREF_JOURNAL="log-journal",DFAdventureLogConfig.PREF_JOURNAL_GM="gmlog-journal",DFAdventureLogConfig.PREF_CONFIG="log-config-menu"},"./src/logger/DFAdventureLogProcessor.ts":(e,t,a)=>{a.r(t),a.d(t,{default:()=>DFAdventureLogProcessor});var r=a("../common/Settings.ts"),i=a("./src/edit/DFChatEditor.ts"),o=a("./src/logger/DFAdventureLogConfig.ts");String.prototype.trimStart||(String.prototype.trimStart=function(){const e=[" ","\n","\r"];let t=-1;for(let a=0;ae!==this[a]));a++)t=a;return this.substr(t+1)});class DFAdventureLogProcessor{static appendChatContextMenuOptions(e){e.push({name:"DF_CHAT_LOG.ContextMenu_AsEvent",icon:'',condition:()=>{const e=r.default.get(DFAdventureLogProcessor.PREF_ENABLE),t=game.user.isGM,a=r.default.get(DFAdventureLogProcessor.PREF_GMONLY);return e&&(!a||t)},callback:e=>{const t=ui.chat.collection.get($(e).attr("data-message-id"));return DFAdventureLogProcessor.commandProcessor(t.content,!1,!1),{}}}),e.push({name:"DF_CHAT_LOG.ContextMenu_AsQuote",icon:'',condition:()=>{const e=r.default.get(DFAdventureLogProcessor.PREF_ENABLE),t=game.user.isGM,a=r.default.get(DFAdventureLogProcessor.PREF_GMONLY);return e&&(!a||t)},callback:e=>{const t=ui.chat.collection.get($(e).attr("data-message-id"));return t.content.trimStart().startsWith('"')?DFAdventureLogProcessor.commandProcessor("q "+t.content,!1,!1):DFAdventureLogProcessor.commandProcessor(`q "${game.users.get(t.user).name}" ${t.content}`,!1,!1),{}}}),e.push({name:"DF_CHAT_LOG.ContextMenu_AsGmEvent",icon:'',condition:()=>{const e=r.default.get(DFAdventureLogProcessor.PREF_ENABLE),t=game.user.isGM;return e&&t},callback:e=>{const t=ui.chat.collection.get($(e).attr("data-message-id"));return DFAdventureLogProcessor.commandProcessor(t.content,!0,!1),{}}}),e.push({name:"DF_CHAT_LOG.ContextMenu_AsGmQuote",icon:'',condition:()=>{const e=r.default.get(DFAdventureLogProcessor.PREF_ENABLE),t=game.user.isGM;return e&&t},callback:e=>{const t=ui.chat.collection.get($(e).attr("data-message-id"));return t.content.trimStart().startsWith('"')?DFAdventureLogProcessor.commandProcessor("q "+t.content,!0,!1):DFAdventureLogProcessor.commandProcessor(`q "${game.users.get(t.user).name}" ${t.content}`,!0,!1),{}}})}static setupSettings(){var e;r.default.register(DFAdventureLogProcessor.PREF_ENABLE,{scope:"world",name:"DF_CHAT_LOG.Setting.EnableTitle",hint:"DF_CHAT_LOG.Setting.EnableHint",config:!0,type:Boolean,default:!0,onChange:e=>{!e&&DFAdventureLogProcessor.logCommand?DFAdventureLogProcessor.deregisterCommand():DFAdventureLogProcessor.registerCommand()}}),r.default.register(DFAdventureLogProcessor.PREF_GMONLY,{name:"DF_CHAT_LOG.Setting.GmOnlyTitle",hint:"DF_CHAT_LOG.Setting.GmOnlyHint",scope:"world",type:Boolean,default:!1,config:!0,onChange:e=>{e&&!game.user.isGM?DFAdventureLogProcessor.deregisterCommand():DFAdventureLogProcessor.registerCommand()}}),r.default.register(DFAdventureLogProcessor.PREF_GMONLY_WHISPER,{name:"DF_CHAT_LOG.Setting.GmOnlyWhisperName",hint:"DF_CHAT_LOG.Setting.GmOnlyWhisperHint",scope:"world",type:Boolean,default:!1,config:!0}),r.default.register(DFAdventureLogProcessor.PREF_USE_TIME,{scope:"world",type:Boolean,name:"DF_CHAT_LOG.Setting.UseTimeName",hint:"DF_CHAT_LOG.Setting.UseTimeHint",default:!0,config:!0}),r.default.register(DFAdventureLogProcessor.PREF_MESSAGES,{name:"DF_CHAT_LOG.Setting.PrintMessagesName",hint:"DF_CHAT_LOG.Setting.PrintMessagesHint",scope:"world",type:Boolean,default:!0,config:!0}),r.default.register(DFAdventureLogProcessor.PREF_SORTDESC,{name:"DF_CHAT_LOG.Setting.SortDescendingName",hint:"DF_CHAT_LOG.Setting.SortDescendingHint",scope:"world",type:Boolean,default:!1,config:!0,onChange:()=>this.resortLog()}),r.default.register(DFAdventureLogProcessor.PREF_DISABLE_FORMATTING,{name:"DF_CHAT_LOG.Setting.DisableFormatName".localize(),hint:"DF_CHAT_LOG.Setting.DisableFormatHint".localize(),config:!0,scope:"world",type:Boolean,default:!1}),r.default.register(DFAdventureLogProcessor.PREF_DISABLE_AUTHOR,{name:"DF_CHAT_LOG.Setting.DisableEntryAuthorName".localize(),hint:"DF_CHAT_LOG.Setting.DisableEntryAuthorHint".localize(),config:!0,scope:"world",type:Boolean,default:!1}),(null===(e=game.modules.get("foundryvtt-simple-calendar"))||void 0===e?void 0:e.active)&&r.default.register(DFAdventureLogProcessor.PREF_SIMPLE_CALENDAR,{scope:"world",type:Boolean,name:"DF_CHAT_LOG.Setting.SimpleCalendarName",hint:"DF_CHAT_LOG.Setting.SimpleCalendarHint",default:!1,config:!0}),Hooks.on("closeDFAdventureLogConfig",(()=>{DFAdventureLogProcessor.logConfig=null})),game.chatCommands?DFAdventureLogProcessor.registerCommand():Hooks.on("chatCommandsReady",(function(){DFAdventureLogProcessor.registerCommand()}))}static deregisterCommand(){game.chatCommands.deregisterCommand(DFAdventureLogProcessor.logCommand),game.chatCommands.deregisterCommand(DFAdventureLogProcessor.plogCommand),DFAdventureLogProcessor.gmlogCommand&&game.chatCommands.deregisterCommand(DFAdventureLogProcessor.gmlogCommand),DFAdventureLogProcessor.logCommand=null,DFAdventureLogProcessor.plogCommand=null,DFAdventureLogProcessor.gmlogCommand=null}static registerCommand(){r.default.get(DFAdventureLogProcessor.PREF_ENABLE)&&(r.default.get(DFAdventureLogProcessor.PREF_GMONLY)&&!game.user.isGM||DFAdventureLogProcessor.logCommand||(DFAdventureLogProcessor.logCommand=game.chatCommands.createCommandFromData({commandKey:"/log",invokeOnCommand:async(e,t,a)=>await DFAdventureLogProcessor.commandProcessor(t,!1,!1),shouldDisplayToChat:!1,iconClass:"fa-edit",description:"DF_CHAT_LOG.CommandDescription".localize()}),game.chatCommands.registerCommand(DFAdventureLogProcessor.logCommand),DFAdventureLogProcessor.plogCommand=game.chatCommands.createCommandFromData({commandKey:"/plog",invokeOnCommand:async(e,t,a)=>await DFAdventureLogProcessor.commandProcessor(t,!1,!0),shouldDisplayToChat:!1,iconClass:"fa-edit",description:"DF_CHAT_LOG.PCCommandDescription".localize()}),game.chatCommands.registerCommand(DFAdventureLogProcessor.plogCommand),game.user.isGM&&(DFAdventureLogProcessor.gmlogCommand=game.chatCommands.createCommandFromData({commandKey:"/gmlog",invokeOnCommand:async(e,t,a)=>await DFAdventureLogProcessor.commandProcessor(t,!0,!1),shouldDisplayToChat:!1,iconClass:"fa-edit",description:"DF_CHAT_LOG.GMCommandDescription".localize()}),game.chatCommands.registerCommand(DFAdventureLogProcessor.gmlogCommand))))}static _getTimestamp(){var e;const t=r.default.get(DFAdventureLogProcessor.PREF_USE_TIME);if((null===(e=game.modules.get("foundryvtt-simple-calendar"))||void 0===e?void 0:e.active)&&r.default.get(DFAdventureLogProcessor.PREF_SIMPLE_CALENDAR)){const e=SimpleCalendar.api.formatDateTime(SimpleCalendar.api.timestampToDate(SimpleCalendar.api.timestamp()));return t?`${e.date} ${e.time}`:e.date}return t?(new Date).toLocaleString("sv").replace(",","").replace(/ ([AP])/,"$1"):(new Date).toLocaleString("sv").replace(",","").replace(/ ([AP])/,"$1").split(" ")[0]}static async commandProcessor(e,t,a,s=!1){var n;const l=(e=e.trim()).split(" ");if(!r.default.get(DFAdventureLogProcessor.PREF_ENABLE))return game.chatCommands.deregisterCommand(DFAdventureLogProcessor.logCommand),void ui.notifications.warn("DF_CHAT_LOG.Error.Disabled".localize());if(0==e.length||l.every((e=>0==e.length)))return void setTimeout((async()=>{await Dialog.prompt({title:"DF_CHAT_LOG.HelpDialog_Title".localize(),label:"OK",callback:()=>{},content:await renderTemplate(`modules/df-chat-enhance/templates/lang/log-help.${"DF_CHAT_ENHANCE.LANG".localize()}.hbs`,{isGM:game.user.isGM}),options:{width:800}})}),1);const c=ChatMessage.getSpeaker({user:game.user}),d={flavor:"",user:game.user.id,speaker:c,type:CONST.CHAT_MESSAGE_TYPES.OOC,content:""};let g;const h=r.default.get(DFAdventureLogProcessor.PREF_DISABLE_FORMATTING),u=a||r.default.get(DFAdventureLogProcessor.PREF_DISABLE_AUTHOR);switch(l[0].toLowerCase()){case"config":return game.user.isGM?void setTimeout((async()=>{DFAdventureLogProcessor.logConfig?DFAdventureLogProcessor.logConfig.bringToTop():(DFAdventureLogProcessor.logConfig=new o.default({}),DFAdventureLogProcessor.logConfig.render(!0))}),1):void ui.notifications.warn("DF_CHAT_LOG.Error.ConfigGmOnly".localize());case"q":case"quote":let t;if(e=e.replace(l[0],"").trimStart(),'"'===l[1][0]&&'"'!==l[1][l[1].length-1]){let a=-1;for(let t=1;t$("#chat-message").val("/log q "+e)),1);t=e.slice(0,a+1),e=e.slice(a+1).trimStart()}else t=l[1];if(e=i.default.processMarkdown(e)[1].replace(t,"").trim(),t=t.replace(/"/gm,""),d.flavor=`${game.user.name} quoted ${t}`,d.content=`${e}`,0==e.length)return ui.notifications.error("DF_CHAT_LOG.Error.MissingMessage".localize()),void setTimeout((()=>$("#chat-message").val(`/log q "${t}" ${e}`)),1);g="DF_CHAT_LOG.Log_Quote",h&&(g+="_Bland"),u&&(g+="_NoAuth"),g=g.localize(),g=g.replace("{0}",this._getTimestamp()),g=g.replace("{1}",game.user.name),g=g.replace("{2}",t),e=g.replace("{3}",e);break;case"e":case"event":e=e.replace(l[0],"").trim();default:e=i.default.processMarkdown(e)[1].trim(),d.flavor="Event Logged",d.content=`${e}`,g="DF_CHAT_LOG.Log_Event",h&&(g+="_Bland"),u&&(g+="_NoAuth"),g=g.localize(),g=g.replace("{0}",this._getTimestamp()),g=g.replace("{1}",game.user.name),e=g.replace("{2}",e)}const m=null===(n=a?game.user.getFlag(r.default.MOD_NAME,this.PREF_PLAYER_LOG_JOURNAL):r.default.get(t?o.default.PREF_JOURNAL_GM:o.default.PREF_JOURNAL))||void 0===n?void 0:n.split(".");if(!m||!game.journal.has(m[0]))return void(a?ui.notifications.error("DF_CHAT_LOG.Error.NoPlayerJournalSet".localize()):game.user.isGM?ui.notifications.error("DF_CHAT_LOG.Error.NoJournalSetGM".localize(),{permanent:!0}):ui.notifications.warn("DF_CHAT_LOG.Error.NoJournalSet".localize()));const f=game.journal.get(m[0]).pages.get(m[1]);let _=$(f.text.content);const p=$(e);let C=_.find("section.df-adventure-log");0==C.length&&(await o.default.initializeJournal(m.join("."),!1,t,a),_=$(f.text.content),C=_.find("section.df-adventure-log"));r.default.get(this.PREF_SORTDESC)?C.prepend(p):C.append(p),await f.update({"text.content":$("
    ").append(_).html()});const A=game.settings.get("core","rollMode");game.user.isGM&&("publicroll"!==A||r.default.get(DFAdventureLogProcessor.PREF_GMONLY)&&r.default.get(DFAdventureLogProcessor.PREF_GMONLY_WHISPER))&&(d.whisper=[game.user.id]),(a||t)&&(d.whisper=[game.user.id]),!s&&r.default.get(DFAdventureLogProcessor.PREF_MESSAGES)&&await ChatMessage.create(d,{})}static async resortLog(){var e,t;const a=r.default.get(this.PREF_SORTDESC),i=null===(e=r.default.get(o.default.PREF_JOURNAL))||void 0===e?void 0:e.split("."),s=null===(t=r.default.get(o.default.PREF_JOURNAL_GM))||void 0===t?void 0:t.split("."),journalSort=async e=>{var t;const r=$(null===(t=e.text)||void 0===t?void 0:t.content),i=r.find("article.df-adventure-log"),o=i.find("p").sort((function(e,t){return a?$(t).find("span.dfal-ts").text().localeCompare($(e).find("span.dfal-ts").text()):$(e).find("span.dfal-ts").text().localeCompare($(t).find("span.dfal-ts").text())}));i.html(o),await e.update({"text.content":$("
    ").append(r).html()})};game.journal.has(i[0])&&await journalSort(game.journal.get(i[0]).pages.get(i[1])),game.journal.has(s[0])&&await journalSort(game.journal.get(s[0]).pages.get(s[1]))}}DFAdventureLogProcessor.PREF_ENABLE="enable-command",DFAdventureLogProcessor.PREF_GMONLY="df-log-gmonly",DFAdventureLogProcessor.PREF_GMONLY_WHISPER="df-log-gmonly-whisper",DFAdventureLogProcessor.PREF_MESSAGES="df-log-messages",DFAdventureLogProcessor.PREF_SORTDESC="df-log-sortdesc",DFAdventureLogProcessor.PREF_DISABLE_FORMATTING="df-log-disable-format",DFAdventureLogProcessor.PREF_DISABLE_AUTHOR="df-log-disable-author",DFAdventureLogProcessor.PREF_SIMPLE_CALENDAR="df-log-use-simple-calendar",DFAdventureLogProcessor.PREF_USE_TIME="df-log-use-time",DFAdventureLogProcessor.PREF_PLAYER_LOG_JOURNAL="PlayerAdventureLog",DFAdventureLogProcessor.logCommand=null,DFAdventureLogProcessor.gmlogCommand=null,DFAdventureLogProcessor.plogCommand=null,DFAdventureLogProcessor.logConfig=null},"./src/logger/df-adventure-log.ts":(e,t,a)=>{a.r(t),a.d(t,{init:()=>init,ready:()=>ready});var r=a("../common/libWrapperShared.ts"),i=a("../common/Settings.ts"),o=a("./src/logger/DFAdventureLogConfig.ts"),s=a("./src/logger/DFAdventureLogProcessor.ts");function init(){const e={event:async function(e,t=!1){s.default.commandProcessor("event "+e,!1,!1,!t)}.bind(s.default),pevent:async function(e,t=!1){s.default.commandProcessor("event "+e,!1,!0,!t)}.bind(s.default),gmevent:async function(e,t=!1){game.user.isGM?s.default.commandProcessor("event "+e,!0,!1,!t):ui.notifications.warn("DF_CHAT_LOG.Error.ApiLog_NotGm".localize())}.bind(s.default),quote:async function(e,t,a=!1){s.default.commandProcessor(`quote "${e}" ${t}`,!1,!1,!a)}.bind(s.default),pquote:async function(e,t,a=!1){s.default.commandProcessor(`quote "${e}" ${t}`,!1,!0,!a)}.bind(s.default),gmquote:async function(e,t,a=!1){game.user.isGM?s.default.commandProcessor(`quote "${e}" ${t}`,!0,!1,!a):ui.notifications.warn("DF_CHAT_LOG.Error.ApiLog_NotGm".localize())}.bind(s.default)};window.AdventureLog=e}function ready(){var e;(null===(e=game.modules.get("lib-wrapper"))||void 0===e?void 0:e.active)&&(o.default.setupSettings(),s.default.setupSettings(),Hooks.on("renderUserConfig",((e,t,a)=>{var r;const o=null===(r=a.user.getFlag(i.default.MOD_NAME,s.default.PREF_PLAYER_LOG_JOURNAL))||void 0===r?void 0:r.split("."),n=Handlebars.compile('\n
    \n\t\n\t
    \n\t\t\n\t
    \n
    \n
    \n\t\n\t
    \n\t\t\n\t
    \n
    \n'),l=ui.journal.documents.filter((e=>e.testUserPermission(a.user,CONST.DOCUMENT_PERMISSION_LEVELS.OBSERVER))).filter((e=>e.pages.contents.some((e=>"text"===e.type)))),c=$(n({selected:null!=o?o:"",journals:[{id:"",name:"---",selected:!o}].concat(l.map((e=>({id:e.id,name:e.name,selected:e.id===o[0]})))),pages:o?l.find((e=>e.id==o[0])).pages.contents.filter((e=>"text"===e.type)).map((e=>({id:e.id,name:e.name,selected:e.id===o[1]}))):[]},{allowProtoMethodsByDefault:!0,allowProtoPropertiesByDefault:!0}));t.find("#characters").parent().before(c),c.find("#dfce-player-log").on("change",(e=>{const t=e.currentTarget.value,a=c.find("#dfce-player-log-page");if(a.children().remove(),t&&0!==t.length)for(const e of game.journal.get(t).pages.contents.filter((e=>"text"===e.type)))a.append(``)}))})),r.default.register("UserConfig.prototype._updateObject",(async function(e,t,a){return await this.object.setFlag(i.default.MOD_NAME,s.default.PREF_PLAYER_LOG_JOURNAL,a["player-log-page"]),await e(t,a)})),async function migrateDataV9toV10(){if(!game.user.isGM)return;let e=i.default.get(o.default.PREF_JOURNAL);checkJournal(e)&&await i.default.set(o.default.PREF_JOURNAL,await migrateJournalV9toV10(e));e=i.default.get(o.default.PREF_JOURNAL_GM),checkJournal(e)&&await i.default.set(o.default.PREF_JOURNAL_GM,await migrateJournalV9toV10(e));for(const t of game.users)e=t.getFlag(i.default.MOD_NAME,s.default.PREF_PLAYER_LOG_JOURNAL),checkJournal(e)&&(e=await migrateJournalV9toV10(e),e?await t.setFlag(i.default.MOD_NAME,s.default.PREF_PLAYER_LOG_JOURNAL,e):await t.unsetFlag(i.default.MOD_NAME,s.default.PREF_PLAYER_LOG_JOURNAL))}())}function checkJournal(e){return e&&e.split(".").length<2}async function migrateJournalV9toV10(e){const t=game.journal.get(e);if(!t)return null;const a=t.pages.contents.find((e=>"text"==e.type));return a?t.id+"."+a.id:null}},"./src/merge/chat-merge.ts":(e,t,a)=>{a.r(t),a.d(t,{default:()=>ChatMerge});var r=a("../common/libWrapperShared.ts"),i=a("../common/Settings.ts"),o=a("./src/archive/DFChatArchiveManager.ts");class ChatMerge{static get _enabled(){return i.default.get(this.PREF_ENABLED)}static get _epoch(){return i.default.get(this.PREF_EPOCH)}static get _allowRolls(){return i.default.get(this.PREF_ALLOW_ROLLS)}static get _separateWithBorder(){return i.default.get(this.PREF_SEPARATE)}static get _showHover(){return i.default.get(this.PREF_HOVER)}static get _showHeader(){return i.default.get(this.PREF_SHOW_HEADER)}static init(){i.default.register(this.PREF_ENABLED,{name:"DF_CHAT_MERGE.EnableName",hint:"DF_CHAT_MERGE.EnableHint",config:!0,scope:"client",default:!0,type:Boolean,onChange:()=>this._processAllMessage()}),i.default.register(this.PREF_SHOW_HEADER,{name:"DF_CHAT_MERGE.ShowHeaderName",hint:"DF_CHAT_MERGE.ShowHeaderHint",config:!0,scope:"client",default:!1,type:Boolean,onChange:e=>{const t=document.querySelector(":root").style;t.setProperty("--dfce-cm-header",e?"":"none"),game.user.isGM&&(t.setProperty("--dfce-cm-header-delete",e?"":"0"),t.setProperty("--dfce-cm-header-delete-pad",e?"":"16px"))}}),i.default.register(this.PREF_SPLIT_SPEAKER,{name:"DF_CHAT_MERGE.SplitSpeakerName",hint:"DF_CHAT_MERGE.SplitSpeakerHint",config:!0,scope:"client",default:!0,type:Boolean,onChange:()=>this._processAllMessage()}),i.default.register(this.PREF_ALLOW_ROLLS,{name:"DF_CHAT_MERGE.AllowRollsName",hint:"DF_CHAT_MERGE.AllowRollsHint",config:!0,scope:"client",default:"rolls",type:String,choices:{none:"DF_CHAT_MERGE.AllowRollsOptions.none".localize(),rolls:"DF_CHAT_MERGE.AllowRollsOptions.rolls".localize(),all:"DF_CHAT_MERGE.AllowRollsOptions.all".localize()},onChange:()=>this._processAllMessage()}),i.default.register(this.PREF_SEPARATE,{name:"DF_CHAT_MERGE.SeparateName",hint:"DF_CHAT_MERGE.SeparateHint",config:!0,scope:"client",default:!1,type:Boolean,onChange:e=>{document.querySelector(":root").style.setProperty("--dfce-cm-separation",e?"":"0")}}),i.default.register(this.PREF_HOVER,{name:"DF_CHAT_MERGE.HoverName",hint:"DF_CHAT_MERGE.HoverHint",config:!0,scope:"client",default:!0,type:Boolean,onChange:e=>{const t=document.querySelector(":root").style;e?t.removeProperty("--dfce-cm-hover-shadow"):t.setProperty("--dfce-cm-hover-shadow","0px")}}),i.default.register(this.PREF_EPOCH,{name:"DF_CHAT_MERGE.EpochName",hint:"DF_CHAT_MERGE.EpochHint",config:!0,scope:"client",default:10,type:Number,range:{min:1,max:60,step:1},onChange:()=>this._processAllMessage()}),r.default.register("ChatLog.prototype.deleteMessage",this._deleteMessage.bind(this)),Hooks.on("renderChatMessage",this._renderChatMessage)}static ready(){const e=document.querySelector(":root").style;e.setProperty("--dfce-cm-separation",this._separateWithBorder?"":"0"),this._showHover?e.removeProperty("--dfce-cm-hover-shadow"):e.setProperty("--dfce-cm-hover-shadow","0px"),e.setProperty("--dfce-cm-header",this._showHeader?"":"none"),game.user.isGM&&(e.setProperty("--dfce-cm-header-delete",this._showHeader?"":"0"),e.setProperty("--dfce-cm-header-delete-pad",this._showHeader?"":"16px")),this._processAllMessage(ui.chat.element),Hooks.on("renderChatLog",((e,t)=>this._processAllMessage(t))),Hooks.on("renderDFChatArchiveViewer",((e,t)=>this._processAllMessage(t)))}static _deleteMessage(e,t,{deleteAll:a=!1}={}){var r,i,o;if(!a&&this._enabled){const e=document.querySelector(`li[data-message-id="${t}"`);(null===(r=null==e?void 0:e.classList)||void 0===r?void 0:r.contains("dfce-cm-top"))?(e.classList.remove("dfce-cm-top"),e.nextElementSibling.classList.contains("dfce-cm-middle")?(e.nextElementSibling.classList.remove("dfce-cm-middle"),e.nextElementSibling.classList.add("dfce-cm-top")):e.nextElementSibling.classList.remove("dfce-cm-bottom")):(null===(i=null==e?void 0:e.classList)||void 0===i?void 0:i.contains("dfce-cm-bottom"))?(e.classList.remove("dfce-cm-bottom"),e.previousElementSibling.classList.contains("dfce-cm-middle")?(e.previousElementSibling.classList.remove("dfce-cm-middle"),e.previousElementSibling.classList.add("dfce-cm-bottom")):e.previousElementSibling.classList.remove("dfce-cm-top")):(null===(o=null==e?void 0:e.classList)||void 0===o?void 0:o.contains("dfce-cm-middle"))&&e.classList.remove("dfce-cm-middle")}return e(t,{deleteAll:a})}static _processAllMessage(e){if((e=null!=e?e:$(document.body)).find(".dfce-cm-top").removeClass("dfce-cm-top"),e.find(".dfce-cm-middle").removeClass("dfce-cm-middle"),e.find(".dfce-cm-bottom").removeClass("dfce-cm-bottom"),!ChatMerge._enabled)return;const t=e.find("li.chat-message");if(0!==t.length){t[0].hasAttribute("style")&&t[0].style.setProperty("--dfce-mc-border-color",t[0].style.borderColor);for(let e=1;et&&e-t<1e3*this._epoch}static _isValidMessage(e,t){const a=this._allowRolls,r=i.default.get(this.PREF_SPLIT_SPEAKER);let o=!1;const s=e,n=t;return!((null==s?void 0:s.flags)&&s.flags["midi-qol"]||(null==n?void 0:n.flags)&&n.flags["midi-qol"])&&(o=r?s.speaker.actor===n.speaker.actor&&!!s.speaker.actor||!s.speaker.actor&&!n.speaker.actor&&s.user===n.user:s.user===n.user,o&&this._inTimeFrame(s.timestamp,n.timestamp)&&("all"===a||"rolls"===a&&e.isRoll===t.isRoll||"none"===a&&!e.isRoll&&!t.isRoll))}static _styleChatMessages(e,t,a,r){if(t.hasAttribute("style")&&t.style.setProperty("--dfce-mc-border-color",t.style.borderColor),void 0===e&&void 0===a){const i=parseInt(/df-chat-log-(\d+)/.exec(t.parentElement.parentElement.id)[1]);if(isNaN(i))return;const s=o.default.chatViewers.get(i);e=s.messages.find((e=>{var a;return(null!==(a=e.id)&&void 0!==a?a:e._id)==t.dataset.messageId})),a=s.messages.find((e=>{var t;return(null!==(t=e.id)&&void 0!==t?t:e._id)==r.dataset.messageId}))}ChatMerge._isValidMessage(e,a)&&(r.classList.contains("dfce-cm-bottom")?(r.classList.remove("dfce-cm-bottom"),r.classList.add("dfce-cm-middle")):r.classList.add("dfce-cm-top"),t.classList.add("dfce-cm-bottom"))}}ChatMerge.PREF_ENABLED="chat-merge-enabled",ChatMerge.PREF_SPLIT_SPEAKER="chat-merge-split-speaker",ChatMerge.PREF_EPOCH="chat-merge-epoch",ChatMerge.PREF_ALLOW_ROLLS="chat-merge-allowRolls",ChatMerge.PREF_SEPARATE="chat-merge-separateWithBorder",ChatMerge.PREF_HOVER="chat-merge-showhover",ChatMerge.PREF_SHOW_HEADER="chat-merge-showheader"},"./src/player-color/PlayerColor.ts":(e,t,a)=>{a.r(t),a.d(t,{default:()=>PlayerColor});var r=a("../common/libWrapperShared.ts"),i=a("../common/Settings.ts"),o=a("./src/Util.ts");class PlayerColor{static init(){i.default.register(PlayerColor.PREF_TINT_BG,{config:!0,name:"DF_CHAT_PLAYER_COLOR.SettingTintBackgroundName",hint:"DF_CHAT_PLAYER_COLOR.SettingTintBackgroundHint",scope:"world",type:Boolean,default:!1,onChange:o.default.reloadChatLog}),i.default.register(PlayerColor.PREF_BORDER_STYLE,{name:"DF_CHAT_PLAYER_COLOR.SettingBorderStyleName",hint:"DF_CHAT_PLAYER_COLOR.SettingBorderStyleHint",config:!0,type:String,choices:{all:"DF_CHAT_PLAYER_COLOR.BorderStyle.all",mine:"DF_CHAT_PLAYER_COLOR.BorderStyle.mine",none:"DF_CHAT_PLAYER_COLOR.BorderStyle.none"},default:"all",scope:"client",onChange:o.default.reloadChatLog}),Hooks.on("renderUserConfig",((e,t,a)=>{var r;const o=null!==(r=a.user.getFlag(i.default.MOD_NAME,PlayerColor.FLAG_CHAT_COLOR))&&void 0!==r?r:"";t.find('input[name="color"]').parent().parent().after(`\n
    \n\t\n\t
    \n\t\t\n\t\t\n\t
    \n
    `);const s=t.find("#chat-color"),n=t.find('[data-edit="chat-color"]');s.on("change",(()=>n.val(s.val()))),e.element[0].style.height="",e.setPosition({})})),r.default.register("UserConfig.prototype._updateObject",(async function(e,t,a){await this.object.setFlag(i.default.MOD_NAME,PlayerColor.FLAG_CHAT_COLOR,a["chat-color"]),await e(t,a)})),libWrapper.register(i.default.MOD_NAME,"ChatMessage.prototype.getHTML",(async function(e,...t){var a;const r=await e(...t);if(!this.user)return r;let o=null===(a=this.user.getFlag(i.default.MOD_NAME,PlayerColor.FLAG_CHAT_COLOR))||void 0===a?void 0:a.trim();o&&/#[a-fA-F0-9]{6,8}/.test(o)||(o=this.user.color);let s="#6f6c66";switch(i.default.get(PlayerColor.PREF_BORDER_STYLE)){case"none":break;case"mine":if(game.userId!==this.data.user)break;case"all":s=o}return r[0].style.borderColor=s,r[0].style.setProperty("--dfce-mc-border-color",s),i.default.get(PlayerColor.PREF_TINT_BG)&&(r[0].style.backgroundColor=o,r[0].style.backgroundImage="url(../ui/parchment.jpg)",r[0].style.backgroundRepeat="repeat",r[0].style.backgroundBlendMode="screen"),r}),"WRAPPER")}}PlayerColor.PREF_TINT_BG="PlayerColor_TintBackground",PlayerColor.PREF_BORDER_STYLE="PlayerColor.BorderStyle",PlayerColor.FLAG_CHAT_COLOR="chat-color"},"./src/privacy/df-chat-privacy.ts":(e,t,a)=>{a.r(t),a.d(t,{default:()=>ChatRollPrivacy});var r=a("../common/Settings.ts"),i=a("./src/Util.ts");const o={publicroll:"fas fa-dice-d20",gmroll:"fas fa-user-secret",blindroll:"fas fa-user-ninja",selfroll:"fas fa-ghost"};class ChatRollPrivacy{static setup(){game.keybindings.register(r.default.MOD_NAME,"roll-mode.publicroll",{name:"Public Roll",editable:[{key:"KeyQ",modifiers:[KeyboardManager.MODIFIER_KEYS.ALT]}],namespace:"Roll Type Shortcuts",onDown:()=>{$('#dfcp-rt-buttons > button[data-id="publicroll"]').trigger("click")}}),game.keybindings.register(r.default.MOD_NAME,"roll-mode.gmroll",{name:"Private GM Roll",editable:[{key:"KeyW",modifiers:[KeyboardManager.MODIFIER_KEYS.ALT]}],namespace:"Roll Type Shortcuts",onDown:()=>{$('#dfcp-rt-buttons > button[data-id="gmroll"]').trigger("click")}}),game.keybindings.register(r.default.MOD_NAME,"roll-mode.blindroll",{name:"Blind GM Roll",editable:[{key:"KeyE",modifiers:[KeyboardManager.MODIFIER_KEYS.ALT]}],namespace:"Roll Type Shortcuts",onDown:()=>{$('#dfcp-rt-buttons > button[data-id="blindroll"]').trigger("click")}}),game.keybindings.register(r.default.MOD_NAME,"roll-mode.selfroll",{name:"Self Roll",editable:[{key:"KeyR",modifiers:[KeyboardManager.MODIFIER_KEYS.ALT]}],namespace:"Roll Type Shortcuts",onDown:()=>{$('#dfcp-rt-buttons > button[data-id="selfroll"]').trigger("click")}})}static init(){r.default.register("enabled",{name:"DF_CHAT_PRIVACY.Settings_EnableTitle",hint:"DF_CHAT_PRIVACY.Settings_EnableHint",scope:"client",type:Boolean,default:!0,config:!0,onChange:i.default.requestReload}),r.default.register("replace-buttons",{name:"DF_CHAT_PRIVACY.Settings_ReplaceButtonsTitle",hint:"DF_CHAT_PRIVACY.Settings_ReplaceButtonsHint",scope:"client",type:Boolean,default:!0,config:!0,onChange:i.default.requestReload}),!1!==r.default.get("enabled")&&Hooks.on("renderChatLog",this._handleChatLogRendering)}static calcColour(e,t){return`rgb(${e/t*255},${255*(1-e/t)},0)`}static async _handleChatLogRendering(e,t,a){const i=Object.keys(a.rollModes),s=[],n=Object.keys(o);for(let e=0;ee==t)),n.length)}):console.warn(Error(`Unknown roll type '${t}'`))}const l=$(await renderTemplate("modules/df-chat-enhance/templates/privacy-button.hbs",{buttons:s}));if(l.find("button").on("click",(function(){const e=$(this).attr("data-id");game.settings.set("core","rollMode",e),l.find("button.active").removeClass("active"),$(this).addClass("active")})),t.find("select[name=rollMode]").after(l),t.find("select[name=rollMode]").remove(),!r.default.get("replace-buttons"))return;l.attr("style","margin:0 0 0 0.5em");let c=!0;t.find("#chat-controls div.control-buttons a").each((function(){const e=$(this).html(),t=$(this).attr("class"),a=$(this).attr("title"),r=$(this).attr("style"),i=$._data(this,"events").click[0].handler,o=$(``);o.on("click",i),c&&(o.attr("style","margin-left:0.5em"),c=!1),l.append(o)})),t.find("#chat-controls div.control-buttons").remove()}}},"./src/scroll-manage/ChatHistoryOptimizer.ts":(e,t,a)=>{a.r(t),a.d(t,{default:()=>ChatHistoryOptimizer});var r=a("../common/Settings.ts"),i=a("./src/Util.ts");class ChatHistoryOptimizer{static init(){r.default.register(this.PREF_ENABLED,{name:"DF_CHAT_SCROLL.HistoryFixEnabledName",hint:"DF_CHAT_SCROLL.HistoryFixEnabledHint",config:!0,type:Boolean,default:!0,scope:"world",onChange:i.default.requestReload}),r.default.register(this.PREF_HISTORY_SIZE,{name:"DF_CHAT_SCROLL.HistorySizeName",hint:"DF_CHAT_SCROLL.HistorySizeHint",config:!0,type:Number,default:CONFIG.ChatMessage.batchSize,range:{min:CONFIG.ChatMessage.batchSize,max:5*CONFIG.ChatMessage.batchSize,step:CONFIG.ChatMessage.batchSize},scope:"world",onChange:()=>$("#chat-log").trigger("scroll")}),r.default.get(this.PREF_ENABLED)&&libWrapper.register(r.default.MOD_NAME,"ChatLog.prototype._onScrollLog",this._ChatLog_onScrollLog,"MIXED")}static _ChatLog_onScrollLog(e,t){if(!this.rendered)return Promise.resolve();const a=r.default.get(ChatHistoryOptimizer.PREF_HISTORY_SIZE);if(this.collection.size<=CONFIG.ChatMessage.batchSize)return e(t);const i=t.target,o=$(i).find("li.chat-message");let s=-1;const n=i.scrollTop/i.scrollHeight,l=i.scrollTop+o[0].offsetTop;let c=Math.trunc(o.length*n);if(o[c].offsetTop=l||c-1>=0&&o[c].offsetTop>=l&&o[c-1].offsetTop+o[c-1].offsetHeight){s=c;break}}else for(;c>=0;c--)if(o[c].offsetTop<=l&&o[c].offsetTop+o[c].offsetHeight>=l||c-1>=0&&o[c].offsetTop>=l&&o[c-1].offsetTop+o[c-1].offsetHeight){s=c;break}if(s<0)return Promise.resolve();if(sa){const e=s-(a-1);this._lastId=o[e].dataset.messageId,o.slice(0,e).remove()}return Promise.resolve()}static _displayMessageCounts(e){ChatHistoryOptimizer._lastFrame+500{a.r(t),a.d(t,{default:()=>ScrollManage});var r=a("../common/libWrapperShared.ts"),i=a("../common/Settings.ts"),o=a("./src/scroll-manage/ChatHistoryOptimizer.ts");class ScrollManage{static get enabled(){return i.default.get(this.PREF_ENABLED)}static get scrollToBottomIfYouSendMessage(){return i.default.get(this.PREF_SCROLL_IF_YOU)}static init(){Hooks.on("renderChatLog",this._renderChatLog.bind(this)),i.default.register(this.PREF_ENABLED,{name:"DF_CHAT_SCROLL.EnableName",hint:"DF_CHAT_SCROLL.EnableHint",scope:"world",config:!0,type:Boolean,default:!0,onChange:e=>{e?this.register():this.unregister()}}),i.default.register(this.PREF_SCROLL_IF_YOU,{name:"DF_CHAT_SCROLL.ScrollIfYouName",hint:"DF_CHAT_SCROLL.ScrollIfYouHint",scope:"world",config:!0,type:Boolean,default:!0}),o.default.init()}static ready(){this.enabled&&this.register()}static register(){libWrapper.register(i.default.MOD_NAME,"ChatLog.prototype.postOne",this._ChatLog_postOne,"OVERRIDE"),libWrapper.register(i.default.MOD_NAME,"ChatLog.prototype.scrollBottom",this._ChatLog_scrollBottom,"OVERRIDE"),this._deleteMessageRegistrationID=r.default.register("ChatLog.prototype.deleteMessage",this._ChatLog_deleteMessage)}static unregister(){libWrapper.unregister(i.default.MOD_NAME,"ChatLog.prototype.postOne",!1),libWrapper.unregister(i.default.MOD_NAME,"ChatLog.prototype.scrollBottom",!1),r.default.unregister("ChatLog.prototype.deleteMessage",this._deleteMessageRegistrationID)}static _renderChatLog(e,t){e._scrollToBottomButton=$(``),e._scrollToBottomButton.on("click",(()=>{const t=e.element,a=t.length?t[0].querySelector("#chat-log"):null;a&&a.scrollTo({behavior:"smooth",top:a.scrollHeight})})),t.find("div#chat-controls").before(e._scrollToBottomButton),t.find("ol#chat-log").on("scroll",(t=>{if(!e._scrollToBottomButton)return;const a=t.currentTarget;a.clientHeight>a.scrollHeight-this.ScrollThreshold||(a.scrollTopt.scrollTo({behavior:"smooth",top:t.scrollHeight})),100):$("#chat #chat-log").trigger("scroll")}static async _ChatLog_postOne(e,t=!1){if(!e.visible)return;this._lastId||(this._lastId=e.id),(e.whisper||[]).includes(game.user.id)&&!e.isRoll&&(this._lastWhisper=e);const a=this.element.find("#chat-log"),r=a[0].scrollTop>=a[0].scrollHeight-a[0].clientHeight-ScrollManage.ScrollThreshold,i=await e.getHTML();a.append(i),r||ScrollManage.scrollToBottomIfYouSendMessage&&e.isAuthor?a[0].scrollTo({top:a[0].scrollHeight,behavior:"smooth"}):this._scrollToBottomButton.addClass("new"),t&&this.notify(e),this._popout&&await this._popout.postOne(e,!1),this.popOut&&this.setPosition()}static _ChatLog_deleteMessage(e,t,{deleteAll:a=!1}={}){const r=e(t,{deleteAll:a});return!a||this._scrollToBottomButton.is(":hidden")||(this._scrollToBottomButton.hide(),this._scrollToBottomButton.removeClass("new")),r}}ScrollManage.PREF_ENABLED="scroll-manage-enabled",ScrollManage.PREF_SCROLL_IF_YOU="scroll-manage-scroll-if-you",ScrollManage.ScrollThreshold=50,ScrollManage._deleteMessageRegistrationID=null},"./src/send/send-button.ts":(e,t,a)=>{a.r(t),a.d(t,{default:()=>SendButton});var r=a("../common/Settings.ts");class SendButton{static init(){r.default.register(this.PREF_ENABLED,{name:"DF_CHAT_SEND_BUTTON.EnabledName".localize(),hint:"DF_CHAT_SEND_BUTTON.EnabledHint".localize(),config:!0,scope:"client",type:Boolean,default:!1,onChange:e=>{if(e){this._renderChatLog(ui.chat,$("#sidebar #chat"));const e=$("#chat-popout");e.length>0&&this._renderChatLog(ui.chat,e)}else $(".dfce-send-btn").remove(),$("#chat-message").each(((e,t)=>{$(t).off("input",t.dfce_handler)}))}}),Hooks.on("renderChatLog",this._renderChatLog.bind(this))}static _renderChatLog(e,t){if(!r.default.get(this.PREF_ENABLED))return;const a=$('');a.attr("title","DF_CHAT_SEND_BUTTON.ButtonTitle".localize()),t.find("#chat-form").append(a);const i=t.find("#chat-message");a.prop("disabled",i[0].textLength<=0||i[0].value.trim().length<=0),a.on("click",(async e=>{e.preventDefault(),await ui.chat._onChatKeyDown({code:"Enter",currentTarget:i[0],originalEvent:{isComposing:!1},preventDefault:()=>{}}),setTimeout((()=>i.trigger("input")),100)}));const handler=e=>{const t=e.currentTarget;a.prop("disabled",t.textLength<=0||t.value.trim().length<=0)};i[0].dfce_handler=handler,i.on("input",handler),i.on("change",handler)}}SendButton.PREF_ENABLED="SendButton.Enabled"},"./src/whisper-trunc/whisper-trunc.ts":(e,t,a)=>{a.r(t),a.d(t,{default:()=>WhisperTruncation});var r=a("../common/Settings.ts");const i=" ".length-1;class WhisperTruncation{static init(){Hooks.on("renderChatMessage",this._messageRender.bind(this)),r.default.register(this.PREF_ENABLED,{name:"DF_CHAT_WHISPER_TRUNC.SettingEnabledName",hint:"DF_CHAT_WHISPER_TRUNC.SettingEnabledHint",config:!0,type:Boolean,default:!0,scope:"world",onChange:async()=>{ui.chat._state=0,ui.chat._lastId=null,await ui.chat.render(!0)}}),r.default.register(this.PREF_CHAR_LIMIT,{name:"DF_CHAT_WHISPER_TRUNC.SettingCharLimitName",hint:"DF_CHAT_WHISPER_TRUNC.SettingCharLimitHint",config:!0,type:Number,default:50,scope:"world",onChange:async()=>{ui.chat._state=0,ui.chat._lastId=null,await ui.chat.render(!0)}})}static _messageRender(e,t,a){if(!r.default.get(this.PREF_ENABLED)||!e.whisper||e.whisper.length<=1)return;const o=e.whisper.map((e=>game.users.get(e)));let s=o[0].name,n=this._formatTitle(s,o.length-1),l=1;const c=r.default.get(this.PREF_CHAR_LIMIT);for(;lc)break;s=e,n=t}if(l===o.length)return;const d=`${n}`;t.find("span.whisper-to").replaceWith(d)}static _formatTitle(e,t){return t>0?"$0: $1 (+$2 more)".replace("$0","CHAT.To".localize()).replace("$1",e).replace("$2",t.toString()):e}}WhisperTruncation.PREF_ENABLED="whisper-trunc_enabled",WhisperTruncation.PREF_CHAR_LIMIT="whisper-trunc_char-limit"}},t={};function __webpack_require__(a){var r=t[a];if(void 0!==r)return r.exports;var i=t[a]={exports:{}};return e[a](i,i.exports,__webpack_require__),i.exports}__webpack_require__.d=(e,t)=>{for(var a in t)__webpack_require__.o(t,a)&&!__webpack_require__.o(e,a)&&Object.defineProperty(e,a,{enumerable:!0,get:t[a]})},__webpack_require__.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),__webpack_require__.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var a={};(()=>{__webpack_require__.r(a);var e=__webpack_require__("./src/archive/df-chat-archive.ts"),t=__webpack_require__("./src/edit/df-chat-edit.ts"),r=__webpack_require__("./src/logger/df-adventure-log.ts"),i=__webpack_require__("./src/logger/DFAdventureLogProcessor.ts"),o=__webpack_require__("./src/merge/chat-merge.ts"),s=__webpack_require__("./src/privacy/df-chat-privacy.ts"),n=__webpack_require__("./src/scroll-manage/scroll-manage.ts"),l=__webpack_require__("../common/Settings.ts"),c=__webpack_require__("./src/whisper-trunc/whisper-trunc.ts"),d=__webpack_require__("./src/player-color/PlayerColor.ts"),g=__webpack_require__("./src/send/send-button.ts"),h=__webpack_require__("./src/font-size/font-size.ts"),u=__webpack_require__("./src/chat-time/chat-time.ts");l.default.init("df-chat-enhance"),Application.prototype._recalculateDimensions=function(){this.element[0].style.height="",this.element[0].style.width="",this.setPosition({})},Hooks.once("setup",(function(){s.default.setup()})),Hooks.once("init",(function(){e.init(),s.default.init(),r.init(),o.default.init(),n.default.init(),c.default.init(),d.default.init(),g.default.init(),h.default.init(),u.default.init(),libWrapper.register(l.default.MOD_NAME,"ChatLog.prototype._getEntryContextOptions",(function(e,...a){const r=e(...a);return t.default.appendChatContextMenuOptions(r),i.default.appendChatContextMenuOptions(r),r}),"WRAPPER")})),Hooks.once("ready",(function(){var e;(null===(e=game.modules.get("lib-wrapper"))||void 0===e?void 0:e.active)||(console.error("Missing libWrapper module dependency"),game.user.isGM&&ui.notifications.error("DF_CHAT_LOG.Error.LibWrapperMissing".localize())),r.ready(),t.default.ready(),o.default.ready(),n.default.ready(),u.default.ready()}))})()})(); //# sourceMappingURL=main.js.map