144export
class Watermark {
159 constructor(filePath:
string | undefined = undefined, cwd:
string | undefined = undefined, alternateFilePath:
string | undefined = undefined) {
162 this.fileInstance.updateFilePath(filePath);
164 if (alternateFilePath) {
165 this.fileInstance.updateAlternateFilePath(alternateFilePath);
168 this.fileInstance.updateCurrentWorkingDirectory(cwd);
181 async updateFilePath(filePath:
string): Promise<boolean> {
183 return await this.fileInstance.updateFilePath(filePath);
185 async updateAlternateFilePath(alternateFilePath:
string): Promise<boolean> {
186 logger.debug(
getMessage(
"inFunction",
"updateAlternateFilePath",
"Watermark"));
187 return await this.fileInstance.updateAlternateFilePath(alternateFilePath);
199 async updateCurrentWorkingDirectory(cwd:
string): Promise<boolean> {
200 logger.debug(
getMessage(
"inFunction",
"updateCurrentWorkingDirectory",
"Watermark"));
201 return await this.fileInstance.updateCurrentWorkingDirectory(cwd);
213 private getRandomNumber(maxValue: number): number {
215 return Math.floor(Math.random() * maxValue);
244 async getRandomWatermark(): Promise<
watermark> {
246 const fileContent = await this.fileInstance.get();
247 if (!Array.isArray(fileContent) || fileContent.length === 0) {
248 const err:
string =
getMessage(
"watermarkJsonFileInvalid");
250 throw new Error(err);
252 const chosenIndex: number = this.getRandomNumber(fileContent.length);
253 const raw = fileContent[chosenIndex];
256 fontName: raw.fontName
280 private copyButtonScript():
string {
284 const vscode = acquireVsCodeApi();
286 document.getElementById(
'copyBtn').addEventListener(
'click', () => {
287 const content = document.getElementById(
'ascii').innerText;
288 navigator.clipboard.writeText(content).then(() => {
316 private zoomScript():
string {
320 let currentSize = 20;
321 function updateFontSize(sizeDifference) {
322 console.log(\`sizeDifference = \${sizeDifference}\`);
323 const asciiPre = document.getElementById(
'ascii');
324 console.log(\`asciiPre = \${JSON.stringify(asciiPre)}\`);
325 console.log(\`currentSize = \${currentSize}\`);
326 if (currentSize + sizeDifference >= 2) {
327 currentSize += sizeDifference;
328 console.log(\`currentSize (after update) = \${currentSize}\`);
330 console.log(\`currentSize (no update) = \${currentSize}\`);
332 asciiPre.style.fontSize = currentSize +
"px";
333 asciiPre.style.lineHeight = currentSize +
"px";
334 console.log(\`newSize = \${asciiPre.style.fontSize}\`);
337 document.getElementById(
'zoomInBtn').addEventListener(
'click', () => {
341 document.getElementById(
'zoomOutBtn').addEventListener(
'click', () => {
342 updateFontSize((-2));
366 private pageStyle():
string {
370 body { font-family: sans-serif; padding: 20px; }
371 h1 { font-size: 20px; margin-bottom: 0.2em; }
372 h2 { margin-top: 1.2em; }
373 pre { font-size: 10px; line-height: 10px; white-space: pre; }
374 button { margin: 10px 0; padding: 5px 12px; font-size: 14px; }
375 .logo { width:150px; height:150px }
414 async displayRandomAuthorWatermarkInWindow() {
415 logger.debug(
getMessage(
"inFunction",
"displayRandomAuthorWatermarkInWindow",
"Watermark"));
416 const randomwatermark:
watermark = await this.getRandomWatermark();
418 const panel =
vscode.window.createWebviewPanel(
420 randomwatermark.fontName,
422 { enableScripts: true }
425 const watermark = randomwatermark.watermark;
436 const copyButton:
string = this.copyButtonScript();
437 const pageStyle:
string = this.pageStyle();
438 const zoomScript:
string = this.zoomScript();
440 panel.webview.html = `
444 <meta charset=
"UTF-8">
448 <p>${
getMessage(
"watermarkAuthorName")}: Henry Letellier</p>
449 <img
class=
"logo" src=
"${authorLogo}"/>
451 <button
id=
"copyBtn">${
getMessage(
'watermarkCopyAscii')}</button>
452 <button
id=
"zoomInBtn">${
getMessage(
'watermarkZoomIn')}</button>
453 <button
id=
"zoomOutBtn">${
getMessage(
'watermarkZoomOut')}</button>
455 <h1>${
getMessage(
'watermarkName')}: ${randomwatermark.fontName}</h1>
456 <pre
id=
"ascii">${asciiArt}</pre>
463 panel.webview.onDidReceiveMessage(message => {
464 if (message.type ===
"copied") {
469 logger.Gui.info(
getMessage(
"watermarkPersonDisplayed", randomwatermark.fontName));
Generic lazy file loader with caching and type safety @template T The expected type of the loaded fil...
export const authorLogo
the base64 logo of the author's icon
Structure representing a loaded ASCII art watermark with font metadata.
export const logger
Singleton logger instance providing unified logging interface for the entire extension.
export const getMessage
Exported function for direct message retrieval.
export const Record< string,(...args:any[])=> string
import *as vscode from vscode