### Install Dependencies and Run Deft Development Server Source: https://github.com/deft-ui/deft-ui.github.io/blob/main/src/content/docs/en/android/quick-start.md Installs project dependencies using npm and starts the development server for live previewing. This command is typically run after initializing the project and its Android components. ```bash npm install npm run dev ``` -------------------------------- ### Install deft-cli and HarmonyOS Targets (Bash) Source: https://github.com/deft-ui/deft-ui.github.io/blob/main/src/content/docs/en/harmony/quick-start.md Installs necessary HarmonyOS targets for Rust and the deft-cli toolkit. Requires rustup and Cargo. ```bash rustup target add aarch64-unknown-linux-ohos rustup target add x86_64-unknown-linux-ohos cargo install deft-cli ``` -------------------------------- ### Set HarmonyOS SDK and DevEco Home Environment Variables (Windows) Source: https://github.com/deft-ui/deft-ui.github.io/blob/main/src/content/docs/en/harmony/quick-start.md Sets the OHOS_SDK_HOME and DEVECO_HOME environment variables on Windows. Replace paths with your actual installation locations. ```bash set OHOS_SDK_HOME=C:\Users\dev\AppData\Local\OpenHarmony\Sdk\15 set DEVECO_HOME=C:\Program Files\Huawei\DevEco Studio ``` -------------------------------- ### Install Deft CLI and Android Targets Source: https://github.com/deft-ui/deft-ui.github.io/blob/main/src/content/docs/en/android/quick-start.md Installs the deft-cli toolkit globally using Cargo and adds the necessary Android cross-compilation targets for Rust. This command assumes you have Rust and Cargo installed and configured. ```bash cargo install deft-cli rustup target add aarch64-linux-android rustup target add x86_64-linux-android ``` -------------------------------- ### Set HarmonyOS SDK and DevEco Home Environment Variables (macOS) Source: https://github.com/deft-ui/deft-ui.github.io/blob/main/src/content/docs/en/harmony/quick-start.md Sets the OHOS_SDK_HOME and DEVECO_HOME environment variables on macOS. Replace paths with your actual installation locations. ```bash export OHOS_SDK_HOME=/Users/dev/Library/OpenHarmony/Sdk/15 export DEVECO_HOME=/Applications/DevEco-Studio.app/Contents ``` -------------------------------- ### Create and Initialize Deft UI Project (Bash) Source: https://github.com/deft-ui/deft-ui.github.io/blob/main/src/content/docs/en/harmony/quick-start.md Creates a new Deft UI project named 'demo' and initializes it for HarmonyOS development. Requires Node.js and npm. ```bash npm create deft@0.7 demo cd demo deft init ohos ``` -------------------------------- ### Create a New Deft Project Source: https://github.com/deft-ui/deft-ui.github.io/blob/main/src/content/docs/en/android/quick-start.md Initializes a new Deft UI project named 'demo' using npm. After creation, you will be prompted to select a language and framework. This command sets up the basic project structure. ```bash npm create deft demo ``` -------------------------------- ### Build Release Version of Deft UI for Android Source: https://github.com/deft-ui/deft-ui.github.io/blob/main/src/content/docs/en/android/quick-start.md Compiles the Deft UI project into a release-ready library for Android. After execution, the `android` directory can be opened in Android Studio for further packaging into a standard Android application. ```bash npm run build:android ``` -------------------------------- ### Build Release Version for HarmonyOS (Bash) Source: https://github.com/deft-ui/deft-ui.github.io/blob/main/src/content/docs/en/harmony/quick-start.md Builds the release version of the HarmonyOS shared library. This can then be packaged into a Harmony application using DevEco Studio. ```bash npm run build:ohos ``` -------------------------------- ### Install Rust using rustup Source: https://github.com/deft-ui/deft-ui.github.io/blob/main/src/content/docs/en/guides/prerequisites.md Installs the Rust programming language toolchain using rustup. This command is suitable for Linux and MacOS environments and does not require root privileges. ```bash curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh ``` -------------------------------- ### Install NodeJS on Debian Source: https://github.com/deft-ui/deft-ui.github.io/blob/main/src/content/docs/en/guides/prerequisites.md Installs NodeJS on Debian-based Linux systems using the apt package manager. It first updates the package list and then installs the NodeJS package. ```bash sudo apt update sudo apt install nodejs ``` -------------------------------- ### Configure MacOS Environment Variables for Android NDK Source: https://github.com/deft-ui/deft-ui.github.io/blob/main/src/content/docs/en/android/quick-start.md Sets the ANDROID_HOME and ANDROID_NDK_HOME environment variables for MacOS systems. Verify that the paths match your actual Android SDK and NDK installation directories. NDK version 26 is currently supported. ```bash export ANDROID_HOME="$HOME/Library/Android/sdk" export ANDROID_NDK_HOME="$ANDROID_HOME/ndk/26.3.11579264" ``` -------------------------------- ### Configure Linux Environment Variables for Android NDK Source: https://github.com/deft-ui/deft-ui.github.io/blob/main/src/content/docs/en/android/quick-start.md Sets the ANDROID_HOME and ANDROID_NDK_HOME environment variables for Linux systems. Ensure the paths are updated to reflect your actual Android SDK and NDK installation locations. NDK version 26 is currently supported. ```bash export ANDROID_HOME="$HOME/Android/Sdk" export ANDROID_NDK_HOME="$ANDROID_HOME/ndk/26.3.11579264" ``` -------------------------------- ### Start Deft Development Server (npm) Source: https://context7.com/deft-ui/deft-ui.github.io/llms.txt Command to start the development server for a Deft project using npm. It also includes shortcuts for previewing the application on desktop or Android. ```bash npm run dev # Press 'r' to start desktop preview # Press 'a' to start Android preview (requires USB debugging enabled) ``` -------------------------------- ### Initialize Android Project within Deft Source: https://github.com/deft-ui/deft-ui.github.io/blob/main/src/content/docs/en/android/quick-start.md Initializes the Android project files within an existing Deft project directory. This command should be run after navigating into the project directory. You will be prompted to enter an AppID. ```bash cd demo deft init android ``` -------------------------------- ### Install Linux Dependencies for Deft-UI Source: https://github.com/deft-ui/deft-ui.github.io/blob/main/src/content/docs/en/guides/prerequisites.md Installs essential build tools and libraries required for Deft-UI on Debian-based Linux systems. This command assumes a Debian 12 environment and may vary for other distributions. ```bash sudo apt install build-essential libssl-dev libclang-dev libc++-dev \ xorg-dev libxcb-xfixes0-dev libxcb-shape0-dev libdbus-1-dev \ libasound2-dev libegl-dev libgles-dev librust-wayland-egl-dev ``` -------------------------------- ### Create Astro Starlight Project Source: https://github.com/deft-ui/deft-ui.github.io/blob/main/README.md This command initializes a new Astro project using the Starlight template. It requires Node.js and npm to be installed. The output is a new project directory configured for Starlight documentation. ```bash npm create astro@latest -- --template starlight ``` -------------------------------- ### Box Model Styling Example (JSX) Source: https://github.com/deft-ui/deft-ui.github.io/blob/main/src/content/docs/en/guides/style.md Provides a JSX example of applying Deft UI's box model properties, including width, height, margin, padding, border, and borderRadius. Deft's box model follows the 'border-box' standard. ```jsx ``` -------------------------------- ### Webpack CSS Import Configuration Source: https://github.com/deft-ui/deft-ui.github.io/blob/main/src/content/docs/en/guides/style.md Illustrates a Webpack configuration for using 'deft-style-loader', 'css-loader', and 'postcss-loader' to import and hot-load CSS files. This setup is similar to the standard 'style-loader' approach. ```javascript module.exports = { ... module: { rules: [ ... { test: /\.css$/, use: [ 'deft-style-loader', 'css-loader', 'postcss-loader'] } ], } }; ``` -------------------------------- ### Astro Project Commands Source: https://github.com/deft-ui/deft-ui.github.io/blob/main/README.md Lists essential npm commands for managing an Astro project, including dependency installation, running a local development server, building for production, and previewing the build. These commands are executed from the project's root directory. ```bash npm install npm run dev npm run build npm run preview npm run astro ... npm run astro -- --help ``` -------------------------------- ### Basic TextInput Usage in React Source: https://github.com/deft-ui/deft-ui.github.io/blob/main/src/content/docs/en/components/text-input.md Demonstrates how to import and use the TextInput component from deft-react in a React application. This example shows basic instantiation with an initial text value. ```javascript import {TextInput} from 'deft-react'; function App() { return } ``` -------------------------------- ### CSS: Style Custom Component Source: https://github.com/deft-ui/deft-ui.github.io/blob/main/src/content/docs/en/advanced/custom-component.mdx Provides basic CSS rules to style a custom component with the tag 'hello'. This example sets dimensions and background color for the component. ```css body { justify-content: center; align-items: center; } hello { width: 100px; height: 100px; background: #ccc; } ``` -------------------------------- ### Flexbox Layout System Example (React) Source: https://context7.com/deft-ui/deft-ui.github.io/llms.txt Demonstrates using Deft's React components and CSS-like flexbox layout system to build a multi-pane application interface. It includes a header, sidebar, main content area, and footer, showcasing layout properties like flexDirection, alignItems, and justifyContent. ```javascript import { Container, Button, Label } from 'deft-react'; function LayoutDemo() { return ( {/* Header */} {/* Main content area */} {/* Sidebar */} {/* Content */} {/* Footer */} ); } ``` -------------------------------- ### Deft HTTP Fetch API (JavaScript) Source: https://context7.com/deft-ui/deft-ui.github.io/llms.txt Shows how to make HTTP requests using a Web-standard fetch interface in Deft. Supports simple GET requests and POST requests with JSON bodies, including response handling. ```javascript // Simple GET request const response = await fetch("https://deft-ui.github.io"); const data = await response.json(); console.log(data); // POST request with JSON body const postResponse = await fetch("https://api.example.com/users", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ name: "John Doe", email: "john@example.com" }) }); if (postResponse.ok) { const result = await postResponse.json(); console.log("User created:", result); } else { console.error("Request failed:", postResponse.status); } ``` -------------------------------- ### JavaScript: Manage System Tray Icons with Deft UI System Tray API Source: https://context7.com/deft-ui/deft-ui.github.io/llms.txt This example uses the Deft UI System Tray API to create and manage system tray icons on PC platforms (Linux, Windows, macOS). It covers setting the icon, title, binding click events, and defining context menu items with handlers. It requires a GUI environment. ```javascript const tray = new SystemTray(); tray.title = "My Deft App"; tray.icon = "assets/icon.png"; tray.bindActivate(() => { console.log("Tray icon clicked"); window.show(); }); tray.setMenus([ { id: "show", label: "Show Window", handler() { console.log("Show menu clicked"); window.show(); } }, { id: "settings", label: "Settings", handler() { console.log("Opening settings..."); } }, { id: "exit", label: "Exit", handler() { process.exit(0); } } ]); ``` -------------------------------- ### LocalStorage Usage in JavaScript Source: https://github.com/deft-ui/deft-ui.github.io/blob/main/src/content/docs/en/api/localstorage.md Demonstrates basic LocalStorage operations in JavaScript. Includes examples for storing key-value pairs using `setItem` and retrieving values using `getItem`. This allows for client-side data persistence. ```javascript // Store data localStorage.setItem("name", "测试"); // Read data const value = localStorage.getItem("name"); ``` -------------------------------- ### Import CSS Stylesheets (JavaScript) Source: https://github.com/deft-ui/deft-ui.github.io/blob/main/src/content/docs/en/guides/style.md Demonstrates how to import CSS stylesheets directly using JavaScript by creating a CSS string and appending it to the document's stylesheet. This method is native and does not rely on bundlers. ```javascript const css = ` .btn { color: #F00; } ` navigator.stylesheet.append(css); ``` -------------------------------- ### Deft UI Combinators Source: https://github.com/deft-ui/deft-ui.github.io/blob/main/src/content/docs/en/styles/selector.md Provides an example of using combinators in Deft UI to select elements based on their relationship to other elements. This enables complex selector patterns. ```css .title .name { color: #F00; } ``` -------------------------------- ### Element Base Class: Component Interaction and Properties (JavaScript) Source: https://context7.com/deft-ui/deft-ui.github.io/llms.txt Demonstrates how to utilize the base Element class from 'deft-react' to interact with UI components. This example shows accessing properties like ID and size, getting bounding rectangle information, focusing elements, and handling common events like click and hover. ```javascript import { Element } from 'deft-react'; // Using base Element properties function CustomComponent() { const elementRef = React.useRef(null); React.useEffect(() => { const element = elementRef.current; // Access element properties console.log("Element ID:", element.id); console.log("Element size:", element.size); console.log("Scroll height:", element.scrollHeight); // Get element bounding rectangle const rect = element.getBoundingClientRect(); console.log("Position:", rect.x, rect.y); console.log("Dimensions:", rect.width, rect.height); // Set focus element.focus(); // Bind events element.addEventListener('click', (e) => { console.log("Clicked at:", e.offsetX, e.offsetY); }); element.addEventListener('mouseenter', () => { element.cursor = 'pointer'; }); element.addEventListener('mouseleave', () => { element.cursor = 'default'; }); element.addEventListener('sizechanged', () => { console.log("New size:", element.size); }); }, []); return ( Interactive Element ); } ``` -------------------------------- ### Transform Rotation Example (JSX) Source: https://github.com/deft-ui/deft-ui.github.io/blob/main/src/content/docs/en/guides/style.md Illustrates applying a CSS transform to rotate an element clockwise by 45 degrees using inline styles in Deft UI with JSX. Other transform functions like translate and scale are also supported. ```jsx // 顺时针旋转45度 ... ``` -------------------------------- ### Container Component: Layout with Flexbox (JavaScript) Source: https://context7.com/deft-ui/deft-ui.github.io/llms.txt Illustrates the use of the Container component from 'deft-react' for creating flexible layouts using flexbox properties. This example shows how to arrange elements vertically and horizontally, and apply background colors and spacing. ```javascript import { Container, Button, Label } from 'deft-react'; function App() { return ( ); } ``` -------------------------------- ### Inline Styles for Centered Layout (JSX) Source: https://github.com/deft-ui/deft-ui.github.io/blob/main/src/content/docs/en/guides/style.md Shows how to apply inline styles in Deft UI using JSX. This example demonstrates setting justifyContent and alignItems to center elements within a Container component, utilizing camel case for style property names. ```jsx Some contents ``` -------------------------------- ### JavaScript: Interact with Clipboard Content using Clipboard API Source: https://context7.com/deft-ui/deft-ui.github.io/llms.txt This snippet demonstrates how to read from and write to the system clipboard using the Deft UI Clipboard API. It uses `async/await` syntax and requires browser or Node.js environment with clipboard access permissions. Examples include writing text, reading text, and a button click handler. ```javascript await navigator.clipboard.writeText("Hello, Deft!"); console.log("Text copied to clipboard"); const clipboardContent = await navigator.clipboard.readText(); console.log("Clipboard content:", clipboardContent); button.addEventListener('click', async () => { await navigator.clipboard.writeText(textInput.text); console.log("Copied:", textInput.text); }); ``` -------------------------------- ### Background Color Styling (JSX) Source: https://github.com/deft-ui/deft-ui.github.io/blob/main/src/content/docs/en/guides/style.md Demonstrates how to set the background color of an element using inline styles in Deft UI with JSX. Currently, it only supports single color values. ```jsx ... ``` -------------------------------- ### TextEdit Component Usage in React Source: https://github.com/deft-ui/deft-ui.github.io/blob/main/src/content/docs/en/components/text-edit.md This snippet demonstrates how to import and use the TextEdit component within a React application. It shows basic usage with an initial text value. Ensure 'deft-react' is installed as a dependency. ```javascript import {TextEdit} from 'deft-react'; function App() { return } ``` -------------------------------- ### Apply Box Model Styles (JSX) Source: https://github.com/deft-ui/deft-ui.github.io/blob/main/src/content/docs/en/styles/overview.md Shows an example of using Deft UI's box model properties like `width`, `height`, `margin`, `padding`, `border`, and `borderRadius` within a `Container` component. It follows the `border-box` model where dimensions include padding and border. ```jsx ... ``` -------------------------------- ### Use Deft UI Checkbox Component in React Source: https://github.com/deft-ui/deft-ui.github.io/blob/main/src/content/docs/en/components/checkbox.md This JavaScript example demonstrates how to import and use the Checkbox component from the 'deft-react' library. It shows how to attach refs to checkboxes to access their state and how to handle the onChange event to log the selection status of multiple checkboxes. ```javascript import {Checkbox} from 'deft-react'; function App() { const javascriptRef = useRef(); const rustRef = useRef(); function onCheckChange(e) { console.log('is javascript checked', javascriptRef.current.value); console.log('is rust checked', rustRef.current.value); } return } ``` -------------------------------- ### JavaScript: Background Task Processing with Worker API Source: https://context7.com/deft-ui/deft-ui.github.io/llms.txt This example shows how to use the Deft UI Worker API to create background threads for CPU-intensive tasks. It includes code for the main thread (creating a worker, sending/receiving messages) and the worker script itself (receiving/processing messages, sending results back). ```javascript // Main thread: Create worker const worker = new Worker("worker-script.js"); // Send message to worker worker.postMessage({ action: "process", data: [1, 2, 3, 4, 5] }); // Receive messages from worker worker.bindMessage((e) => { console.log("Worker result:", e.data); }); // worker-script.js file content: // Receive messages from main thread bindMessage((e) => { const { action, data } = e.data; if (action === "process") { // Perform CPU-intensive calculation const result = data.reduce((sum, val) => sum + val, 0); // Send result back to main thread postMessage({ result }); } }); ``` -------------------------------- ### Astro Starlight Project Structure Source: https://github.com/deft-ui/deft-ui.github.io/blob/main/README.md Illustrates the typical file and directory structure of an Astro project integrated with Starlight. Key directories include `public/` for static assets, `src/content/docs/` for markdown content, and configuration files like `astro.config.mjs`. ```tree .\n├── public/\n├── src/\n│ ├── assets/\n│ ├── content/\n│ │ ├── docs/\n│ └── content.config.ts\n├── astro.config.mjs\n├── package.json\n└── tsconfig.json ``` -------------------------------- ### Deft Window API (JavaScript) Source: https://context7.com/deft-ui/deft-ui.github.io/llms.txt Demonstrates how to create and control application windows in the Deft UI Framework using JavaScript. Includes setting titles, binding resize events, resizing windows (PC only), and configuring preferred renderers. ```javascript // Create a new window const window = new Window(); // Set window title window.title = "My Deft App"; // Bind resize event handler window.bindResize((e) => { console.log("Window dimensions:", e.width, e.height); }); // Resize window (PC only) window.resize({ width: 800, height: 600 }); // Configure preferred renderers const customWindow = new Window({ preferredRenderers: ["GL", "SoftBuffer"] }); ``` -------------------------------- ### Create New Deft Project (npm, pnpm, yarn) Source: https://context7.com/deft-ui/deft-ui.github.io/llms.txt Instructions for creating a new Deft project using different package managers (npm, pnpm, yarn). This is the initial step for any new Deft application development. ```bash # Using npm npm create deft@latest # Using pnpm pnpm create deft@latest # Using yarn yarn create deft ``` -------------------------------- ### Build Production Deft Application (npm) Source: https://context7.com/deft-ui/deft-ui.github.io/llms.txt Command to build a production-ready application for the Deft UI Framework using npm. This command compiles and bundles the project for deployment. ```bash npm run build ``` -------------------------------- ### Create and Configure System Tray Icon (JavaScript) Source: https://github.com/deft-ui/deft-ui.github.io/blob/main/src/content/docs/en/api/tray.md This snippet demonstrates how to create a new SystemTray instance, set its title and icon, bind a click event handler, and define context menus. It requires the SystemTray library. ```javascript const tray = new SystemTray(); tray.title = "My Deft App"; tray.icon = "path/to/icon.png"; // Bind click event tray.bindActivate(() => { console.log("clicked"); }); // Set menus tray.setMenus([ { id: "show", label: "Show", handler() { console.log("show menu is clicked"); } }, { id: "exit", label: "Exit", handler() { process.exit(0); } }, ]); ``` -------------------------------- ### 使用 deft-react Entry 组件 Source: https://github.com/deft-ui/deft-ui.github.io/blob/main/src/content/docs/en/components/entry.md 展示如何在 deft-react 应用中使用 Entry 组件。此代码片段演示了导入 Entry 组件并将其渲染到应用中,初始文本设置为 "Hello"。 ```jsx import {Entry} from 'deft-react'; function App() { return } ``` -------------------------------- ### Deft WebSocket API (JavaScript) Source: https://context7.com/deft-ui/deft-ui.github.io/llms.txt Illustrates how to establish and manage WebSocket connections for persistent communication in Deft. Covers connection opening, sending messages, receiving messages, error handling, and connection closure. ```javascript // Create WebSocket connection const ws = new WebSocket("wss://echo.websocket.org"); // Connection opened handler ws.onopen = () => { console.log("WebSocket connection established"); ws.send("Hello Server!"); }; // Message received handler ws.onmessage = (e) => { console.log("Received message:", e.data); }; // Error handler ws.onerror = (e) => { console.error("WebSocket error:", e); }; // Connection closed handler ws.onclose = (e) => { console.log("Connection closed:", e.code, e.reason); }; ``` -------------------------------- ### Deft SQLite Database API (JavaScript) Source: https://context7.com/deft-ui/deft-ui.github.io/llms.txt Demonstrates local database storage and querying using SQLite in Deft applications. Includes opening/creating database files, creating tables, inserting data with parameterized queries, querying data, updating, and deleting records. ```javascript // Open or create database file const conn = await Sqlite.open("/path/to/app.db"); // Create table await conn.execute( 'CREATE TABLE IF NOT EXISTS "users" ("id" INTEGER PRIMARY KEY, "name" TEXT, "email" TEXT)', [] ); // Insert data with parameterized queries await conn.execute( "INSERT INTO users(id, name, email) VALUES(?, ?, ?)", [1, "Tom", "tom@example.com"] ); await conn.execute( "INSERT INTO users(id, name, email) VALUES(?, ?, ?)", [2, "Alice", "alice@example.com"] ); // Query data const rows = await conn.query("SELECT * FROM users WHERE name LIKE 'T%'"); console.log("Query results:", rows); // Update data await conn.execute( "UPDATE users SET email = ? WHERE id = ?", ["newemail@example.com", 1] ); // Delete data await conn.execute("DELETE FROM users WHERE id = ?", [2]); ``` -------------------------------- ### Basic Select Component Usage in React Source: https://github.com/deft-ui/deft-ui.github.io/blob/main/src/content/docs/en/components/select.md Demonstrates the basic usage of the Deft UI Select component in a React application. It shows how to import the component and provide an array of options for selection. This requires the 'deft-react' library. ```javascript import {Select} from 'deft-react'; function App() { const options = [ {label: "Rust", value: "rust"}, {label: "JavaScript", value: "javascript"}, ] return