Skip to content

Commit

Permalink
feat: add popup background blur enable option
Browse files Browse the repository at this point in the history
  • Loading branch information
gitcpy committed Nov 15, 2024
1 parent 0d68e5d commit 4053bcc
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 5 deletions.
18 changes: 16 additions & 2 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ interface MermaidPopupSetting {
bgColorDark:string;
bgAlpha:string;
bgAlphaStep:Record<string, string>;
bgIsBlur:string;
};

const DEFAULT_SETTINGS: MermaidPopupSetting = {
Expand Down Expand Up @@ -85,7 +86,8 @@ const DEFAULT_SETTINGS: MermaidPopupSetting = {
'0.8':'0.8',
'0.9':'0.9',
'1.0':'1.0'
},
},
bgIsBlur:'1'
};

export default class MermaidPopupPlugin extends Plugin {
Expand Down Expand Up @@ -441,6 +443,7 @@ export default class MermaidPopupPlugin extends Plugin {
const overlay = targetElement.doc.createElement('div');
overlay.classList.add('popup-overlay');
this.setPopupBgAlpha(overlay);
this.setPopupBgBlur(overlay);
// copy target
let targetElementClone = targetElement.cloneNode(true);
let targetElementInPopup = targetElementClone as HTMLElement;
Expand Down Expand Up @@ -498,10 +501,21 @@ export default class MermaidPopupPlugin extends Plugin {
});
}

setPopupBgBlur(_popupElement:HTMLElement){
if (!_popupElement)
return;

let bgIsBlur = this.settings.bgIsBlur;
let cssBgIsBlur = bgIsBlur=='1'?'blur(10px)':'';
_popupElement.setCssStyles({
backdropFilter:cssBgIsBlur
})
}

setPopupBgAlpha(_popupElement:HTMLElement) {
if (!_popupElement)
return;

let alpha = this.settings.bgAlpha;
// 构造新的 rgba 值
let newBgColor;
Expand Down
20 changes: 17 additions & 3 deletions src/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,6 @@ class MermaidPopupSettingTab extends PluginSettingTab {
// bg Alpha title
let titlePpBgA = td_title_a.createEl('h2', { text: 'Popup Background Alpha Value' });
titlePpBgA.classList.add('config-text');
//const rowPpBgAlpha = td_title_a.createDiv({ cls: 'kv-row' });
// bg Alpha settign
new Setting(td_title_a)
.setName('Choose the alpha value')
Expand All @@ -154,13 +153,28 @@ class MermaidPopupSettingTab extends PluginSettingTab {
this.plugin.settings.bgAlpha = value;
await this.plugin.saveSettings();
}

)
});

this.addClass(td_title_a, 'setting-item', 'setting-item-on-top-line');


const td_title_blur = row.createEl('td');
// bg Alpha title
let titleBlur = td_title_blur.createEl('h2', { text: 'Popup Background Blur' });
titleBlur.classList.add('config-text');
// bg Alpha settign
new Setting(td_title_blur)
.setName('Enable blur')
.addToggle(toggle =>
toggle
.setValue(this.plugin.settings.bgIsBlur=='1'?true:false)
.onChange(async (value) => {
this.plugin.settings.bgIsBlur = value?'1':'0';
await this.plugin.saveSettings();
})
);

this.addClass(td_title_blur, 'setting-item', 'setting-item-on-top-line');

// 开启弹窗按钮位置
let title_btn_pos = containerEl.createEl('h2', { text: 'Open Popup Button Relative Position Init' });
Expand Down

0 comments on commit 4053bcc

Please sign in to comment.