varm=Object.defineProperty;varI=Object.getOwnPropertyDescriptor;var_=Object.getOwnPropertyNames;varA=Object.prototype.hasOwnProperty;varU=(o,e)=>{for(varnine)m(o,n,{get:e[n],enumerable:!0})},N=(o,e,n,i)=>{if(e&&typeofe=="object"||typeofe=="function")for(lettof_(e))!A.call(o,t)&&t!==n&&m(o,t,{get:()=>e[t],enumerable:!(i=I(e,t))||i.enumerable});returno};varD=o=>N(m({},"__esModule",{value:!0}),o);varM={};U(M,{default:()=>k});module.exports=D(M);varS=require("obsidian"),r=require("obsidian");varc=require("obsidian"),f={accessToken:"",clientId:"",clientSecret:"",redirectUri:"https://ticktick-quick-add-obsidian-6yawfmvnj-mooshs-projects-0635287d.vercel.app",selectionMode:"line",tagPosition:"append"},u=classextendsc.PluginSettingTab{constructor(e,n){super(e,n),this.plugin=n}display(){let{containerEl:e}=this;e.empty(),this.plugin.settings.accessToken?this.renderConnectedView(e):this.renderSetupView(e)}renderSetupView(e){e.createEl("h2",{text:"Set up TickTick"}),e.createEl("p",{text:"Connect this plugin to your TickTick account in two steps. You only need to do this once."}),newc.Setting(e).setName("Step 1 \u2014 Enter your TickTick app credentials").setHeading();letn=e.createEl("p");n.appendText("Sign in to the ");leti=n.createEl("a",{text:"TickTick Developer Portal",href:"https://developer.ticktick.com/"});i.setAttr("target","_blank"),i.setAttr("rel","noopener"),n.appendText(", create an app, and copy its Client ID and Client Secret into the fields below. In the portal, set the app's Redirect URI to the value shown in the Redirect URI field."),newc.Setting(e).setName("Client ID").addText(t=>t.setPlaceholder("Your Client ID").setValue(this.plugin.settings.clientId||"").onChange(asyncs=>{this.plugin.settings.clientId=s.trim(),awaitthis.plugin.saveSettings()})),newc.Setting(e).setName("Client Secret").addText(t=>(t.inputEl.type="password",t.setPlaceholder("\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022").setValue(this.plugin.settings.clientSecret||"").onChange(asyncs=>{this.plugin.settings.clientSecret=s.trim(),awaitthis.plugin.saveSettings()}),t)),newc.Setting(e).setName("Redirect URI").setDesc("Copy this exact value into your TickTick app's Redirect URI field in the developer portal. Do not add a trailing slash \u2014 the URIs must match exactly. Only change it here if you self-host the callback page.").addText(t=>t.setPlaceholder(f.redirectUri).setValue(this.plugin.settings.redirectUri||"").onChange(asyncs=>{this.plugin.settings.redirectUri=s.trim().replace(/\/+$/,""),awaitthis.plugin.saveSettings()})),newc.Setting(e).setName("Step 2 \u2014 Authorize").setHeading(),e.createEl("p",{text:"Tap Connect, then tap the link in the popup to sign in to TickTick and approve access. The callback page will either return you to Obsidian automatically, or show you an authorization code \u2014 if you see a code, copy it and paste it in the field below."}),newc.Setting(e).setName("Connect to TickTick").addButton(t=>{t.setButtonText("Connect").setCta().onClick(async()=>{awaitthis.plugin.startAuthFlow()})}),newc.Setting(e).setName("Authorization code").setDesc("Only needed if the callback page showed you a code instead of returning you to Obsidian automatically.").addText(t=>t.setPlaceholder("Paste authorization code").onChange(asyncs=>{s.trim()&&(awaitthis.plugin.exchangeAuthCodeForToken(s.trim()),t.setValue(""),this.display())}))}renderConnectedView(e){e.createEl("h2",{text:"Connected to TickTick"}),e.createEl("p",{text:'Use the "Create TickTick task" command from any note to send the current line or paragraph to TickTick.'}),newc.Setting(e).setName("Plugin behavior").setHeading(),newc.Setting(e).setName("Selection mode").setDesc("Capture only the current line or the entire paragraph.").addDropdown(t=>t.addOption("line","Current line").addOption("paragraph","Entire paragraph").setValue(this.plugin.settings.selectionMode).onChange(asyncs=>{this.plugin.settings.selectionMode=s,awaitthis.plugin.saveSettings()})),newc.Setting(e).setName("Tag position").setDesc("Wherethe#tickticktagisad
`;return{text:s.trim(),start:n,end:i}}function O(o){return o.replace(/!\[([^\]]*)\]\([^)]*\)/g,"$1").replace(/\[([^\]]+)\]\([^)]*\)/g,"$1").replace(/\[\[([^\]|]+)\|([^\]]+)\]\]/g,"$2").replace(/\[\[([^\]]+)\]\]/g,"$1").replace(/^\s*(?:>\s*|#{1,6}\s+|[-*+]\s+\[[ xX]\]\s+|[-*+]\s+|\d+\.\s+)+/,"").replace(/__([^_]+)__/g,"$1").replace(/\*\*?|~~|==|`/g,"").replace(/\s+/g," ").trim()}asyncfunction$(){leto=y(64),n=newTextEncoder().encode(o),i=awaitcrypto.subtle.digest("SHA-256",n),t=(0,S.arrayBufferToBase64)(i).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"");return{codeVerifier:o,codeChallenge:t}}varx=classextendsr.Modal{constructor(n,i){super(n);this.authUrl=i}onOpen(){let{contentEl:n}=this;n.empty(),n.createEl("h2",{text:"Authorize TickTick"}),n.createEl("p",{text:"Tap the link below to open the TickTick login page. After you approve access, you will be returned to Obsidian automatically."});leti=n.createEl("a",{text:"Open TickTick login",href:this.authUrl});i.setAttr("target","_blank"),i.setAttr("rel","noopener"),i.style.display="inline-block",i.style.marginTop="0.5em",i.style.fontWeight="bold"}onClose(){this.contentEl.empty()}};functionw(o,e,n){console.log(JSON.stringify({timestamp:newDate().toISOString(),plugin:"ticktick-integration",action:e,...n,clientId:o.settings.clientId?"***":void0,accessToken:o.settings.accessToken?"***":void0}))}vark=classextendsr.Plugin{asynconload(){console.log("Loading TickTick Plugin"),awaitthis.loadSettings(),this.addSettingTab(newu(this.app,this)),this.registerObsidianProtocolHandler("ticktick-callback",asynce=>{if(!e.code){newr.Notice("TickTick auth failed: no authorization code returned.");return}if(!this.settings.tempState||e.state!==this.settings.tempState){newr.Notice("TickTick auth failed: state mismatch. Please try connecting again.");return}awaitthis.exchangeAuthCodeForToken(e.code)}),this.addCommand({id:"create-ticktick-task",name:"Create TickTick task",icon:"lucide-circle-check-big",editorCallback:(e,n)=>this.createTaskFromEditor(e,n)}),this.registerEvent(this.app.workspace.on("file-menu",(e,n)=>{if(!(ninstanceofr.TFile)||n.extension!=="md")return;leti=this.app.workspace.getActiveViewOfType(r.MarkdownView);!i||!i.editor||i.file!==n||e.addItem(t=>{t.setTitle("Create TickTick task").setIcon("lucide-circle-check-big").onClick(async()=>{awaitthis.createTaskFromEditor(i.editor,i)})})}))}asynccreateTaskFromEditor(e,n){leti=e.getCursor();if(!n.file){newr.Notice("No file found for the current view!");return}lett,s,a;if(this.settings.selectionMode==="paragraph"){let{text:h,start:g,end:E}=V(e,i.line);t=h,s=g,a=E}else{let{text:h,line:g}=R(e,i.line);t=h,s=g,a=g}if(!t.trim()){newr.Notice("No text found on the current line!");return}letd=y(8),l=this.settings.tagPosition==="prepend"?`#ticktick ${t} ^${d}`:`${t} #ticktick ^${d}`;e.replaceRange(l,{line:s,ch:0},{line:a,ch:e.getLine(a).length});letp=this.app.vault.getName(),C=n.file.path,b=`obsidian://advanced-uri?vault=${encodeURIComponent(p)}&filepath=${encodeURIComponent(C)}&block=${encodeURIComponent(d)}`,v=`${t}