const vscode = require('vscode'); const { generateCss } = require('./src/fluidTypography'); const { insertTextAtSelectionValue } = require('./src/webviewText'); const DEFAULT_SIZE_LINES = `text-14px: 12px-14px text-16px: 14px-16px text-18px: 16px-18px text-20px: 18px-20px text-22px: 20px-22px text-25px: 22px-25px text-30px: 25px-30px text-35px: 30px-35px text-38px: 35px-38px text-40px: 38px-40px text-45px: 40px-45px text-50px: 45px-50px text-70px: 50px-70px text-75px: 70px-75px`; function getNonce() { const possible = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; let text = ''; for (let index = 0; index < 32; index += 1) { text += possible.charAt(Math.floor(Math.random() * possible.length)); } return text; } async function openGeneratedCss(css) { const document = await vscode.workspace.openTextDocument({ content: css, language: 'css', }); await vscode.window.showTextDocument(document, { preview: false }); } function getExtensionSettings() { const config = vscode.workspace.getConfiguration('fluidTypography'); return { css: config.get('cssMode', 'tailwind'), round: config.get('round.enabled', true), roundValue: config.get('round.value', '2px'), low: config.get('breakpoints.low', 360), high: config.get('breakpoints.high', 1920), }; } async function generateFromText(input) { try { await openGeneratedCss(generateCss(input, getExtensionSettings())); vscode.window.showInformationMessage('Fluid typography CSS generated.'); } catch (error) { vscode.window.showErrorMessage(`Fluid typography input error: ${error.message}`); } } async function generateFromFile() { const selection = await vscode.window.showOpenDialog({ canSelectFiles: true, canSelectFolders: false, canSelectMany: false, filters: { Text: ['txt', 'md', 'css'], All: ['*'], }, title: 'Select fluid typography settings file', }); if (!selection || selection.length === 0) { return; } const bytes = await vscode.workspace.fs.readFile(selection[0]); await generateFromText(Buffer.from(bytes).toString('utf8')); } async function generateFromSelection() { const editor = vscode.window.activeTextEditor; if (!editor) { vscode.window.showWarningMessage('Open a settings file or select settings text first.'); return; } const selectedText = editor.document.getText(editor.selection); const input = selectedText || editor.document.getText(); await generateFromText(input); } function getWebviewHtml(webview, settings) { const nonce = getNonce(); const { cspSource } = webview; const initialState = { ...settings, sizes: DEFAULT_SIZE_LINES, }; return `