chalk.ist
repository·main·Indexed 23 days ago
https://github.com/idered/chalk.istA tool for creating high-quality images of source code featuring customizable backdrops, CSS gradients, and SVG filters. It includes utilities for managing code, markdown, and note blocks, a color conversion system (HSL/RGB to Hex), and integration with Shiki for custom syntax highlighting themes. Supports exporting editor frames as high-resolution PNGs or copying them to the clipboard.
What's inside chalk.ist
- Chalk.ist is a tool designed to create beautiful images of your source code. You can access the hosted application at https://chalk.ist.
Set up the Chalk.ist development environment
mainTo run the project locally for development, install the dependencies using
pnpmand then start the development server.pnpm install pnpm run devConfigure Drizzle Kit with defineConfig
mainUse the
defineConfigfunction fromdrizzle-kitto create a configuration object for managing your database schema and migrations. This configuration specifies the database dialect, the location of your schema file, and the output directory for generated migrations.import { defineConfig } from "drizzle-kit"; export default defineConfig({ dialect: "postgresql", schema: "./server/database/schema.ts", out: "./server/database/migrations", });Configure the chalk.ist store schema
mainThe
storeobject is a reactive state managed via@vueuse/core'suseStorage, persisted under the key"chalk-store". It defines the visual configuration for the chalk.ist application, including themes, typography, window styles, and layout settings. Developers can interact with this store to manage application state or extend the configuration schema.Key configuration categories include:
- Typography:
fontFamily,fontLigatures,fontSize, andlineHeight. - Theme & Colors:
colorTheme,useCustomTheme,customTheme(an object containing syntax highlighting colors), andsolidBackground. - Window Appearance:
windowStyle,lightWindowStyle,windowBackgroundOpacity,windowBorderRadius,windowNoise, andwindowControls(e.g.,WindowControls.MacOutline). - Layout & Padding:
frameWidth,frameHeight,innerPaddingX,innerPaddingY,paddingX, andpaddingY. - Visual Effects:
backdrop,backdropNoise,reflection,shadowOverlay,showParticles, andshowWatermark. - Branding:
name,username,picture,socialIcon, andwatermark.
- Typography:
Convert HSL/HSLA to Hex
mainThehslToHexfunction converts an HSL or HSLA color string into a Hexadecimal string. If an alpha channel is provided in anhsla()string, it is converted to an 8-digit hex code.Manage code blocks with block management functions
mainTheapp/lib/block.tsmodule provides utility functions for managing different types of content blocks (Code, Markdown, and Notes) within thepersistentState. These functions allow for retrieving, adding, moving, and removing blocks from the application state.Download the editor frame as a PNG
mainUsedownloadPNG()to capture the element marked with the[data-editor-frame]attribute and trigger a browser download of the resulting image asscreenshot.png. The function uses a high scale (4x) for high-resolution output. During the process, the globalstate.exportStateis updated to reflect the lifecycle:PreparingToDownload->JustDownloaded->Idle(after 1 second).Move or remove blocks
mainYou can manipulate the order or existence of blocks using their unique IDs:
moveBlock(blockId, moveBy): Changes the position of a block within the list.moveByis an integer representing the direction and distance (e.g.,1to move down,-1to move up). The move is ignored if the resulting index is out of bounds.removeBlock(blockId): Deletes the block associated with the provided ID from the state.
Retrieve code blocks
mainUsegetCodeBlocks()to retrieve an array of all blocks that are of typeBlockType.Code. UsegetCodeBlock(id)to find a specific code block by its unique identifier. If the ID does not exist or the block is not a code block,getCodeBlockreturnsnull.Convert CSS gradients to CanvasGradient
mainThe
cssGradientToCanvasfunction parses CSS gradient strings (specificallylinear-gradientandconic-gradient) and converts them into aCanvasGradientobject for use with aCanvasRenderingContext2D.Supported formats:
linear-gradient: Uses the first numeric value in the string as the angle.conic-gradient: Supports color stops with angle offsets (e.g.,hsl(0, 100%, 50%) 45deg).
Copy text to the clipboard
mainUse
copyTextToClipboard(text: string)to copy a string to the user's clipboard.Implementation Details:
- It primarily uses the modern
navigator.clipboard.writeTextAPI. - If the Clipboard API is unavailable or fails, it automatically falls back to a legacy method using a temporary
textareaanddocument.execCommand("copy")to ensure compatibility.
- It primarily uses the modern
Check language loading status
mainThe
useShikicomposable provides two helper functions to track the status of language assets:isLanguageLoaded(lang: string): Returnstrueif the specified language has already been successfully loaded.isLanguageLoading(lang: string): Returnstrueif the specified language is currently in the process of being loaded.