Introduction

dframework is a lightweight JavaScript framework for building modern web applications with minimal configuration.

Installation

npm install -g @dstrn825/dframework

Getting Started

To create a new project:

dstrn init
cd my-project
dstrn config
dstrn serve

Core Commands

init

Creates a new project:

dstrn init

After initialization, you can configure your project using the dstrn config command.

config

Configure project settings:

dstrn config

serve

Start a development server:

dstrn serve

The server is accessible at http://localhost:8250.

build

Build for production:

dstrn build

Resource Creation

dframework provides several commands to create different types of resources for your project. Each command initiates an interactive prompt to gather information about the resource you want to create.

function

Functions are structured as serverless handlers with proper error handling and can interact with the database using the MongoAPI if enabled.

Create a new function:

dstrn create function

component

Components are based on the web components standard and can be customized with attributes, methods, and event listeners.

Create a new component:

dstrn create component

manager

Managers are singleton JavaScript objects that can be used for state management, feature coordination, or as service providers.

Create a new manager:

dstrn create manager

script

Create a new script:

dstrn create script

Scripts can be included in all pages, specific pages, or none.

page

Create a new page:

dstrn create page

Pages can be automatically wired up to the routing system if enabled.

style

Create a new style:

dstrn create style

Stylesheets can be bundled together for optimized delivery or kept separate.

Configuration Management

The configuration file is dstrn.conf.js which is created when you run dstrn init and can be modified through dstrn config or by directly editing the file.

Blacklist Management

The blacklist determines which files to ignore in the build process:

// dstrn.conf.js
module.exports = {
    // other config options...
    "blacklist": [
        "node_modules/",
        ".netlify/", 
        ".vscode/",

        "file.js",
        "folder/"
    ]
}

Blacklisted paths can be modified using the blacklist command: dstrn blacklist add/remove ./path/to/file

Exceptions Management

Exceptions override the default build behavior:

// dstrn.conf.js
module.exports = {
    // other config options...
    "exceptions": [
        "functions/",

        "file.js",
        "folder/"
    ]
}

Excepted paths can be modified using the exceptions command: dstrn exceptions add/remove ./path/to/file

Entries Management

Define entry points for specific file processing:

// dstrn.conf.js
module.exports = {
    // other config options...
    "entries": [
        "./views/index.html"
    ]
}

Entry points can be modified using the entries command: dstrn entries add/remove ./path/to/file
Multiple entries can be specified for multi-page applications.

Configuration Options

The following options can be set in your dstrn.conf.js file:

Option Type Default Description
inputDir String ./ The source directory containing your project files
outputDir String ./build The directory where built files will be placed
minify Boolean true Enable JavaScript and CSS minification
obfuscate Boolean true Enable code obfuscation
moveWASMToRoot Boolean true Move WebAssembly (WASM) files to the root directory for better compatibility
apiEndpoint String /api The endpoint path for API requests
useRouter Boolean true Enable the web history router for single-page application routing
cssBundle Array [] List of CSS files to bundle together
jsBundle Array [] List of JavaScript files to bundle together
entries Array [] HTML files to process as entry points
exceptions Array ["functions/"] Files or directories to exclude from processing
blacklist Array ["node_modules/", "build/", ".netlify/", ".vscode/", ".gitignore", "dstrn.conf.js"] Files or directories to exclude from the build

Project Structure

The dframework project structure follows a modular organization as follows:

project-root/
├── functions/              # reusable JavaScript functions
│   ├── example/           # example function implementations
│   └── lib/               # library-specific functions
│
├── lib/                    # core framework libraries
│   ├── dstrn.css          # core CSS framework styles
│   └── dstrn.js           # core JavaScript framework functionality
│
├── public/                 # public assets served directly
│   ├── assets/            # image and file assets
│   ├── css/               # compiled and third-party CSS files
│   └── js/                # compiled and third-party JavaScript files
│
├── views/                  # HTML templates and view files
│   ├── error.html         # error page template
│   └── index.html         # main entry point HTML template
│
├── dstrn.conf.js           # framework configuration file
└── .gitignore              # git ignore configuration

CSS Utility Classes

dframework provides a comprehensive set of utility classes help you style your applications quickly and consistently. The utility classes follow a simple naming convention and are organized into categories for easy use.

Theming

  • Theme classes: .dark-theme, .light-theme
  • Color variables:
    - Base colors: --base, --container-1 through --container-4
    - Accent colors: --accent-1 through --accent-3, --inactive-accent
    - Text colors: --link-color, --binary-color, --primary-text, --secondary-text, --indicator-text
    More color variables and themes can always be added.

Layout Utilities

  • Basic display: .d-none, .d-block, .d-inline, .d-inline-block, .d-grid, .d-contents
  • Table display: .d-table, .d-table-cell, .d-table-row

Flexbox

  • Container types: .flex-row, .flex-column, .flex-center
  • Flex properties: .flex-1, .flex-0, .flex-wrap, .flex-grow
  • Justify content: .justify-between, .justify-around, .justify-evenly, .justify-center, .justify-start, .justify-end
  • Align items: .align-between, .align-around, .align-evenly, .align-center, .align-start, .align-end
  • Gap utilities: .g-0 through .g-5 (in 1em increments)

Positioning

  • Position type: .relative, .absolute, .fixed, .sticky
  • Special positioning: .absolute-center, .absolute-fill
  • Edge positioning: .top-0, .right-0, .bottom-0, .left-0
  • Transform utilities: .translateX, .translateY

Sizing Utilities

  • Percentage width: .w-5 through .w-100 (in 5% increments), .w-100vw
  • Special width: .w-auto, .w-fit, .w-min, .w-max, .w-fill
  • Min/max width: .min-w-*, .max-w-* (same increments as width)
  • Percentage height: .h-5 through .h-100 (in 5% increments), .h-100svh
  • Special height: .h-auto, .h-fit, .h-min, .h-max, .h-fill
  • Min/max height: .min-h-*, .max-h-* (same increments as height)

Spacing Utilities

  • Padding (all sides): .p-0, .p-05, .p-1, .p-2, .p-3, .p-4, .p-5 (in 1em increments)
  • Padding (vertical/horizontal): .py-*, .px-* (in 1em increments)
  • Padding (individual sides): .pt-* (top), .pb-* (bottom), .pl-* (left), .pr-* (right)
  • Margin (all sides): .m-0, .m-05, .m-1, .m-2, .m-3, .m-4, .m-5, .m-auto (in 1em increments)
  • Margin (vertical/horizontal): .my-*, .mx-* (including .mx-auto for centering)
  • Margin (individual sides): .mt-* (top), .mb-* (bottom), .ml-* (left), .mr-* (right)

Typography

  • Font size: .fs-05 through .fs-10
  • Text alignment: .text-center
  • Text style: .bold, .thin
  • Text orientation: .text-vertical
  • Overflow text: .overflow-ellipsis

JavaScript Utility Functions

dframework provides a set of utility functions to simplify common JavaScript operations:

DOM Manipulation

  • select(selector, scope) - query selector wrapper
  • selectAll(selector, scope) - query selector all wrapper that returns an array
  • listen(target, event, callback, ...options) - event listener
  • listenAll(targets, event, callback, ...options) - add event listener to multiple elements

Class Management

  • addClass(element, className) - add a CSS class
  • removeClass(element, className) - remove a CSS class
  • toggleClass(element, className) - toggle a CSS class

Array and String Operations

  • move(input, from, to) - move item in array or character in string
  • remove(input, index) - remove item at index
  • replace(input, index, newItem) - replace item at index
  • limit(input, limit) - limit array length or string length
  • uniquify(input) - remove duplicates from array or string
  • asyncForEach(array, callback) - async version of forEach

Type Checking

  • isUndefined(value) - check if value is undefined
  • isNull(value) - check if value is null
  • isBoolean(value) - check if value is boolean
  • isNumber(value) - check if value is number
  • isInteger(value) - check if value is integer
  • isString(value) - check if value is string
  • isEmpty(value) - check if string or array is empty
  • isFunction(value) - check if value is function
  • isArray(value) - check if value is array
  • isObject(value) - check if value is object
  • hasValue(value) - check if value exists (not empty, null, or undefined)

Utility Functions

  • random(min, max) - generate random integer between min and max
  • storage.get(key, defaultValue) - get item from localStorage
  • storage.set(key, value) - set item in localStorage
  • storage.remove(key) - remove item from localStorage
  • storage.clear() - clear localStorage
  • sleep(milliseconds) - promise-based delay
  • clipboard(text) - copy text to clipboard
  • uniqueId(length) - generate unique ID
  • distance(a, b) - calculates the difference between 2 strings, 2 arrays or 2 objects
  • formatDate(value) - formats any date or date string into a readable format
  • localizeDate(value) - converts any date or date string into the local timezone

Components

dframework provides several custom HTML components. These components offer reusable UI elements with consistent styling and behavior.

dButton

button haptics disabled icon left icon right

Button component with icon support.

Attributes

  • text - button text
  • icon - FontAwesome icon class
  • iconPosition - position of the icon ("left" or "right", default: "left")
  • color - button background color
  • textColor - button text color
  • hoverColor - button hover background color
  • hoverTextColor - button hover text color
  • disabledColor - button disabled background color
  • disabledTextColor - button disabled text color
  • haptics - enable haptic feedback on click
  • disabled - set button to disabled state

Methods

  • setDisabled(toggle) - enable/disable the button
  • setText(text) - change the button text
  • setIcon(icon) - change the button icon
  • setColor(color) - change the button background color
  • setTextColor(color) - change the button text color
  • setHoverColor(color) - change the button hover background color
  • setHoverTextColor(color) - change the button hover text color

dCheckbox

Attributes

  • type - checkbox style (1: toggle switch, 2: checkmark box, default: 1)
  • text - checkbox text
  • activeColor - active state color
  • textColor - label text color
  • inactiveColor - inactive state color

Methods

  • setText(text) - change the checkbox text
  • setActiveColor(color) - change the active state color
  • setInactiveColor(color) - change the inactive state color
  • setTextColor(color) - change the label text color

Events

  • change - fired when checkbox state changes

dColorPicker

Attributes

  • name - color picker label
  • value - initial color value (default: "#000000")
  • colorId - ID for the color input field (default: "color0")
  • opened - whether the color picker is initially opened
  • haptics - enable haptic feedback on selection

Methods

  • set(value) - set the color value
  • get() - get the current color value

Events

  • colorchange - fired when color value changes

dCombobox

option 1
  • option 1
  • option 2
  • option 3
double click
  • double click
  • option 1
  • option 2

Combobox component with optional input support.

Attributes

  • options - JSON string of options array with format [{value: "value1", text: "text 1"}, ...]
  • allowInput - allow text input in the dropdown
  • haptics - enable haptic feedback on selection

Methods

  • setOptions(options) - update the available options
  • set(value) - set the selected value
  • get() - get the currently selected value

Events

  • change - fired when selection changes

dContextMenu

right click

Context menu component that appears on right-click.

Methods

  • openCloseMenu(event) - open or close the context menu
  • openMenu() - open the context menu
  • closeMenu() - close the context menu

Events

  • click - fired when a context menu item is clicked

dDrawer

open/close drawer

this is the drawer content

Slide-out drawer component for additional content or navigation.

Attributes

  • direction - direction from which the drawer appears ("top", "right", "bottom", "left", default: "right")
  • opened - whether the drawer is initially opened

Methods

  • handleOpenClose() - toggle the drawer open/closed state

dDropdown

dropdown

this is the dropdown content

Collapsible dropdown component for grouping content.

Attributes

  • header - text for the dropdown header
  • opened - whether the dropdown is initially opened
  • haptics - enable haptic feedback on toggle

Methods

  • handleOpenClose() - toggle the dropdown open/closed state

dIconButton

Attributes

  • icon - font awesome icon class
  • size - font size of the icon
  • color - icon color
  • activeColor - active state color
  • loader - enable loading state capability
  • loading - set initial loading state

Methods

  • switchState(removeClass, addClass) - switch between icon states
  • change(icon) - change the icon
  • setLoading(state) - set the loading state

dImageInput

Input component for selecting and previewing images.

Attributes

  • accept - file types to accept
  • icon - icon for the upload button

Methods

  • reset() - clear the selected image

Events

  • change - fired when an image is selected

dModal

open modal

Modal component for displaying content in a pop-up overlay.

Attributes

  • opened - whether the modal is initially opened

Methods

  • open() - open the modal
  • close() - close the modal

dNotification

trigger notification

Notification component for displaying alerts or messages.

Attributes

  • opened - whether the notification is initially shown

Methods

  • show() - display the notification
  • hide() - hide the notification
  • destroy() - remove the notification from the DOM

dScroll

you're currently using it to read this documentation

Custom scrolling container with a bouncing effect like on MacOS and iOS.

Attributes

  • direction - scroll direction
  • scrollbar-color - scrollbar color
  • scrollbar-hover-color - scrollbar hover color
  • thumb-width - width of the scrollbar thumb
  • thumb-hover-width - width of the scrollbar thumb on hover
  • scrollbar-width - width of the scrollbar track
  • margin-top - top margin for the scrollable content
  • margin-bottom - bottom margin for the scrollable content
  • margin-side - side margin for the scrollbar

Methods

  • updateScrollbar() - update the scrollbar position and size
  • scrollTo(position) - scroll to a specific position
  • append(element) - add an element to the scrollable content

dSlider

Slider component for selecting a value within a range.

Attributes

  • min - minimum value
  • max - maximum value
  • step - step increment
  • value - initial value
  • thumbColor - thumb color
  • fillColor - fill color
  • trackColor - track color
  • sfx - enable sound effects on slide

Methods

  • getValue() - get the current slider value
  • setValue(value) - set the slider value

Events

  • change - fired when slider value changes

dTextInput

Text input component with optional icon.

Attributes

  • placeholder - input placeholder text
  • icon - icon to display inside the input
  • autocomplete - enable browser autocomplete
  • haptics - enable haptic feedback on focus
  • password - set input type to password

Methods

  • getValue() - get the current input value
  • setValue(value) - set the input value

Events

  • change - fired when input value changes
  • keydown, keyup - keyboard events
  • focus, blur - focus events

dToggle

Toggle button group for selecting from multiple options.

Attributes

  • color - button color
  • activeColor - active button color
  • textColor - text color
  • textActiveColor - active text color
  • bgColor - background color
  • haptics - enable haptic feedback on toggle

Methods

  • set(toggle) - set the active toggle (by index or element)
  • get() - get the currently active toggle element

Events

  • change - fired when selection changes

dLoader

Simple loading spinner component.

Advanced Features

Routing

dframework includes a built-in routing system for creating single-page applications with client-side navigation.

Features

  • history API based routing for clean urls
  • automatic page transitions with optional animations
  • route parameters and query string parsing
  • programmatic navigation API
  • no page reloads

Configuration

To enable single-page routing, simply run the command dstrn config and select "yes" when prompted with use the web history router?.
After this, a new router.js file will be created in the root directory of your project.
You can create template HTML files and load them, as well as reload page scripts, when navigating to a new route.
To define a new route, use the following structure:

// router.js
router.on('/xxx', function () {
    render("views/xxx.html", ["public/js/xxx.js"]);
});

This code defines the /xxx route, renders the xxx.html template, and reloads the xxx.js script when the route is accessed.

Custom page transition

When working with a single-page web application it is possible to customize the CSS transition that's played when switching pages.
To do so, you can simply create a custom render() function.

// router.js
const router = new dRouter('/');
router.controller = null;

const render = (template, scripts) => {
    return new Promise((resolve, reject) => {
    if(router.controller) { router.controller.abort(); router.controller = null };
    router.controller = new AbortController();
    const signal = controller.signal;
    
    // your code to run at the start of the transition

    fetch("../"+template, { signal })
        .then(response => {
            if (!response.ok) {
                throw new Error(`failed to fetch ${template}: ${response.status}`);
            }
            return response.text();
        })
        .then(html => {
            setTimeout(() => { // using fake delay for the animation (optional)
                contentContainer.innerHTML = html;
                const existingScripts = document.querySelectorAll("script[data-page-script]");
                existingScripts.forEach(script => script.remove());
        
                if (scripts && scripts.length > 0) {
                    let scriptsLoaded = 0;
            
                    scripts.forEach((url) => {
                        const script = document.createElement("script");
                        script.src = "../" + url + '?cachebuster=' + new Date().getTime();
                        script.dataset.pageScript = true;
                        script.onload = () => {
                            scriptsLoaded++;
                            if (scriptsLoaded === scripts.length) {
                                resolve();
                            }
                        };
                        document.body.appendChild(script);
                    });
                } else {
                    resolve();
                }
                // your code to end the transition
            }, 700);
        })
        .catch(error => {
            reject(error);
        });
    });
};

// example route
router.on('/', function () {
    render("views/index.html", ["public/js/index.js"]);
});
router.resolve();

License

Copyright (c) 2025 dstrn
This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.
To view a copy of this license, visit https://creativecommons.org/licenses/by-nc-sa/4.0/.

this is the modal content

close modal