106 imageContent:
string[],
116 alias:
string[] |
null
134export
class Darling {
147 constructor(filePath:
string | undefined = undefined, cwd:
string | undefined = undefined, alternateFilePath:
string | undefined = undefined) {
150 this.fileInstance.updateFilePath(filePath);
152 if (alternateFilePath) {
153 this.fileInstance.updateAlternateFilePath(alternateFilePath);
156 this.fileInstance.updateCurrentWorkingDirectory(cwd);
168 async updateFilePath(filePath:
string): Promise<boolean> {
170 return await this.fileInstance.updateFilePath(filePath);
172 async updateAlternateFilePath(alternateFilePath:
string): Promise<boolean> {
173 logger.debug(
getMessage(
"inFunction",
"updateAlternateFilePath",
"Darling"));
174 return await this.fileInstance.updateAlternateFilePath(alternateFilePath);
185 async updateCurrentWorkingDirectory(cwd:
string): Promise<boolean> {
186 logger.debug(
getMessage(
"inFunction",
"updateCurrentWorkingDirectory",
"Darling"));
187 return await this.fileInstance.updateCurrentWorkingDirectory(cwd);
198 private getRandomNumber(maxValue: number): number {
200 return Math.floor(Math.random() * maxValue);
212 async getRandomPerson(): Promise<
Person> {
214 const fileContent = await this.fileInstance.get();
215 if (!Array.isArray(fileContent) || fileContent.length === 0) {
216 const err:
string =
getMessage(
"darlingJsonFileInvalid");
218 throw new Error(err);
220 const chosenIndex: number = this.getRandomNumber(fileContent.length);
221 const raw = fileContent[chosenIndex];
228 description: raw.description,
229 imageContent: raw.image_link ?? [],
232 more_information: raw.more_information,
247 private copyButtonScript():
string {
251 const vscode = acquireVsCodeApi();
253 document.getElementById(
'copyBtn').addEventListener(
'click', () => {
254 const content = document.getElementById(
'ascii').innerText;
255 navigator.clipboard.writeText(content).then(() => {
271 private zoomScript():
string {
276 function updateFontSize(sizeDifference) {
277 console.log(\`sizeDifference = \${sizeDifference}\`);
278 const asciiPre = document.getElementById(
'ascii');
279 console.log(\`asciiPre = \${JSON.stringify(asciiPre)}\`);
280 console.log(\`currentSize = \${currentSize}\`);
281 if (currentSize + sizeDifference >= 2) {
282 currentSize += sizeDifference;
283 console.log(\`currentSize (after update) = \${currentSize}\`);
285 console.log(\`currentSize (no update) = \${currentSize}\`);
287 asciiPre.style.fontSize = currentSize +
"px";
288 asciiPre.style.lineHeight = currentSize +
"px";
289 console.log(\`newSize = \${asciiPre.style.fontSize}\`);
292 document.getElementById(
'zoomInBtn').addEventListener(
'click', () => {
296 document.getElementById(
'zoomOutBtn').addEventListener(
'click', () => {
297 updateFontSize((-2));
314 private pageStyle():
string {
318 body { font-family: sans-serif; padding: 20px; }
319 h1 { font-size: 72px; margin-bottom: 0.2em; }
320 h2 { margin-top: 1.2em; }
321 pre { font-size: 10px; line-height: 10px; white-space: pre; }
322 button { margin: 10px 0; padding: 5px 12px; font-size: 14px; }
340 async displayRandomPersonInWindow() {
341 logger.debug(
getMessage(
"inFunction",
"displayRandomPersonInWindow",
"Darling"));
342 const randomPerson:
Person = await this.getRandomPerson();
344 const panel =
vscode.window.createWebviewPanel(
348 { enableScripts: true }
351 const asciiArt = randomPerson.imageContent.join(
"\n");
353 const copyButton:
string = this.copyButtonScript();
354 const pageStyle:
string = this.pageStyle();
355 const zoomScript:
string = this.zoomScript();
357 panel.webview.html = `
361 <meta charset=
"UTF-8">
365 <h1>${randomPerson.name} (${randomPerson.romaji})</h1>
366 <p><b>${
getMessage(
'darlingType')}:</b> ${randomPerson.type}</p>
367 <p><b>${
getMessage(
'darlingAge')}:</b> ${randomPerson.age}</p>
368 <p><b>${
getMessage(
'darlingHeight')}:</b> ${randomPerson.height} | <b>Weight:</b> ${randomPerson.weight}</p>
369 <p><b>${
getMessage(
'darlingAlias')}:</b> ${randomPerson.alias ? randomPerson.alias.join(
", ") :
"None"}</p>
372 <p>${randomPerson.description}</p>
375 <blockquote>${randomPerson.quote}</blockquote>
378 <p><a href=
"${randomPerson.more_information}" target=
"_blank">${randomPerson.more_information}</a></p>
382 <button
id=
"copyBtn">${
getMessage(
'darlingCopyAscii')}</button>
383 <button
id=
"zoomInBtn">${
getMessage(
'darlingZoomIn')}</button>
384 <button
id=
"zoomOutBtn">${
getMessage(
'darlingZoomOut')}</button>
386 <pre
id=
"ascii">${asciiArt}</pre>
393 panel.webview.onDidReceiveMessage(message => {
394 if (message.type ===
"copied") {
Generic lazy file loader with caching and type safety @template T The expected type of the loaded fil...
import *as vscode from vscode
Represents a character from the Darling in the FranXX series.
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