@dstrn825/dframework v1.0.1
Table of Contents
- Introduction
- Installation
- Getting started
- Core commands
- Resource creation
- Configuration management
- Configuration options
- Project structure
- CSS utility classes
- JS utility functions
- Components
- dButton
- dCheckbox
- dColorPicker
- dCombobox
- dContextMenu
- dDrawer
- dDropdown
- dIconButton
- dImageInput
- dModal
- dNotification
- dScroll
- dSlider
- dTextInput
- dToggle
- dLoader
Introduction
dframework is a lightweight JavaScript framework for building modern web applications with minimal configuration. It provides a CLI tool (dstrn) to help with project initialization, development, and building.
Installation
npm install -g @dstrn825/dframeworkGetting started
To start a new project:
dstrn initCore commands
init
Initializes a new dframework project in the current directory.
dstrn initAfter initialization, you can configure your project using the dstrn config command.
config
Configures a new dframework project interactively.
dstrn configThis command:
- guides you through setting up your project configuration via interactive prompts
- allows you to specify input/output directories, minification options, and other build settings
- must be run after the initial
dstrn initcommand to properly configure your project
serve
Starts a local development server for your project.
dstrn serveThis command:
- launches a development server on port 8250
- automatically loads and serves any cloud functions in your project
- provides real-time feedback on server activity and requests
- supports URL rewrites
The server is accessible at http://localhost:8250.
build
Builds your project for production deployment.
dstrn buildResource 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
Creates a serverless function with optional database and utility access.
dstrn create functionFunctions are structured as serverless handlers with proper error handling and can interact with the database using the MongoAPI if enabled.
component
Creates a web component with optional event emitter functionality.
dstrn create componentComponents are based on the web components standard and can be customized with attributes, methods, and event listeners.
manager
Creates a manager object for state or feature management.
dstrn create managerManagers are singleton JavaScript objects that can be used for state management, feature coordination, or as service providers.
script
Creates a JavaScript file with optional bundling and page integration.
dstrn create scriptScripts can be included in all pages, specific pages, or none.
page
Creates an HTML page with optional routing configuration.
dstrn create pagePages can be automatically wired up to the routing system if enabled.
style
Creates a CSS stylesheet with optional bundling.
dstrn create styleStylesheets can be bundled together for optimized delivery or kept separate.
Configuration management
Configuration management in dframework allows you to customize how your project is built.
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
Blacklist management allows you to exclude specific files and directories from 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>
Exceptions management
Exceptions define paths that should be excluded from the bundling, minifying and obfuscating process:
// 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>
Entries management
Entries specify HTML entry files where bundled JS and CSS should be imported:
// 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>
Multiple entries can be specified for multi-page applications.
Configuration options
dframework provides configuration options in the dstrn.conf.js file. You can modify these settings using the dstrn config command or by editing the file directly.
| 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 configurationCSS utility classes
dframework provides a comprehensive set of utility classes to 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,.bright-theme - Color variables:
- Base colors:
--base,--container-1through--container-4 - Accent colors:
--accent-1,--accent-2,--accent-3,--inactive-accent - Text colors:
--link-color,--binary-color,--primary-text,--secondary-text,--indicator-textMore color variables and themes can always be added.
- Base colors:
Layout utilities
Display
- 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,.g-05,.g-1,.g-2,.g-3,.g-4,.g-5(in 1em increments)
Positioning
- Position type:
.relative,.fixed,.sticky,.absolute - Special positioning:
.absolute-center,.absolute-fill - Edge positioning:
.top-0,.bottom-0,.left-0,.right-0 - Transform utilities:
.translateX,.translateY
Sizing utilities
Width
- Percentage width:
.w-5through.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)
Height
- Percentage height:
.h-5through.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) - Vertical/horizontal:
.py-*,.px-*(in 1em increments) - 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) - Vertical/horizontal:
.my-*,.mx-*(including.mx-autofor centering) - Individual sides:
.mt-*(top),.mb-*(bottom),.ml-*(left),.mr-*(right)
Typography
- Font size:
.fs-05through.fs-10(various increments) - Text alignment:
.text-center - Text style:
.bold,.thin - Text orientation:
.text-vertical - Overflow text:
.overflow-ellipsis
Visual styling
Colors
- Background colors:
.bg-base,.bg-container-1through.bg-container-4,.bg-accent-1,.bg-accent-2,.bg-accent-3,.bg-inactive,.bg-binary - Text colors:
.text-link,.text-base,.text-binary,.text-primary,.text-secondary,.text-indicator,.text-accent-1,.text-accent-2,.text-accent-3,.text-inactive - Hover states:
.hover-bg-*,.hover-text-*
Visual properties
- Border radius:
.bdr-0,.bdr-05,.bdr-1,.bdr-2,.bdr-3,.bdr-4,.bdr-5,.bdr-circle - Opacity:
.opacity-0through.opacity-100(in 10% increments) - Background image:
.bg-cover,.bg-contain - Aspect ratio:
.square(1:1 aspect ratio)
Overflow & scrolling
- General overflow:
.overflow-hidden,.overflow-scroll,.overflow-auto,.overflow-visible - Axis-specific:
.overflow-x-*,.overflow-y-* - custom scrollbar styling included by default
Interaction utilities
- Cursor types:
.pointer,.not-allowed - Style resets:
.no-decorations,.no-outline,.no-border - Transitions:
.tr-1through.tr-10,.click-haptic,.click-haptic-med,.click-haptic-small - Animation control:
.preload(prevents animations during page load)
Usage examples
<!-- centered flex container -->
<div class="flex-center p-2 g-1">
<!-- colored button with hover effect -->
<button class="bg-accent-1 text-binary hover-bg-accent-2 p-1 bdr-1">button</button>
<!-- auto-sized container with shadow -->
<div class="w-fit h-auto p-2 m-1">content here</div>
</div>
<!-- absolutely positioned element at bottom right -->
<div class="absolute bottom-0 right-0 m-2">footer</div>JavaScript utility functions
dframework provides a set of utility functions to simplify common JavaScript operations:
DOM manipulation
select(selector, scope)- query selector wrapperselectAll(selector, scope)- query selector all wrapper that returns an arraylisten(target, event, callback, ...options)- event listenerlistenAll(targets, event, callback, ...options)- add event listener to multiple elements
Class management
addClass(element, className)- add a CSS classremoveClass(element, className)- remove a CSS classtoggleClass(element, className)- toggle a CSS class
Array and string operations
move(input, from, to)- move item in array or character in stringremove(input, index)- remove item at indexreplace(input, index, newItem)- replace item at indexlimit(input, limit)- limit array length or string lengthuniquify(input)- remove duplicates from array or stringasyncForEach(array, callback)- async version of forEach
Type checking
isUndefined(value)- check if value is undefinedisNull(value)- check if value is nullisBoolean(value)- check if value is booleanisNumber(value)- check if value is numberisInteger(value)- check if value is integerisString(value)- check if value is stringisEmpty(value)- check if string or array is emptyisFunction(value)- check if value is functionisArray(value)- check if value is arrayisObject(value)- check if value is objecthasValue(value)- check if value exists (not empty, null, or undefined)
Utility functions
random(min, max)- generate random integer between min and maxstorage.get(key, defaultValue)- get item from localStoragestorage.set(key, value)- set item in localStoragestorage.remove(key)- remove item from localStoragestorage.clear()- clear localStoragesleep(milliseconds)- promise-based delayclipboard(text)- copy text to clipboarduniqueId(length)- generate unique IDdistance(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 component with icon support.
Attributes:
text- button texticon- font awesome icon classiconPosition- position of the icon ("left" or "right", default: "left")color- button background colortextColor- button text colorhoverColor- button hover background colorhoverTextColor- button hover text colordisabledColor- button disabled background colordisabledTextColor- button disabled text colorhaptics- enable haptic feedback on clickdisabled- set button to disabled state
Methods:
setDisabled(toggle)- enable/disable the buttonsetText(text)- change the button textsetIcon(icon)- change the button iconsetColor(color)- change the button background colorsetTextColor(color)- change the button text colorsetHoverColor(color)- change the button hover background colorsetHoverTextColor(color)- change the button hover text color
Usage:
<d-button text="submit" icon="fa-solid fa-paper-plane" haptics></d-button>dCheckbox
Attributes:
type- checkbox style (1: toggle switch, 2: checkmark box, default: 1)text- checkbox textactiveColor- active state colortextColor- label text colorinactiveColor- inactive state color
Methods:
setText(text)- change the checkbox textsetActiveColor(color)- change the active state colorsetInactiveColor(color)- change the inactive state colorsetTextColor(color)- change the label text color
Events:
change- fired when checkbox state changes
Usage:
<d-checkbox text="enable something" type="1"></d-checkbox>dColorPicker
Attributes:
name- color picker labelvalue- initial color value (default: "#000000")colorId- id for the color input field (default: "color0")opened- whether the color picker is initially openedhaptics- enable haptic feedback on selection
Methods:
set(value)- set the color valueget()- get the current color value
Events:
colorchange- fired when color value changes
Usage:
<d-color-picker value="#FF5733" name="theme color"></d-color-picker>dCombobox
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 dropdownhaptics- enable haptic feedback on selection
Methods:
setOptions(options)- update the available optionsset(value)- set the selected valueget()- get the currently selected value
Events:
change- fired when selection changes
Usage:
<d-combobox options='[{"value":"red","text":"Red"},{"value":"green","text":"Green"},{"value":"blue","text":"Blue"}]'></d-combobox>dContextMenu
Context menu component that appears on right-click.
Methods:
openCloseMenu(event)- open or close the context menuopenMenu()- open the context menucloseMenu()- close the context menu
Events:
click- fired when a context menu item is clicked
Usage:
<div>
right click
<d-context-menu>
<span>option 1</span>
<span>option 2</span>
<span>option 3</span>
</d-context-menu>
</div>dDrawer
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
Usage:
<d-drawer direction="left">
<div class="p-2">
<h3>drawer example</h3>
<ul>
<li>home</li>
<li>about</li>
<li>contact</li>
</ul>
</div>
</d-drawer>dDropdown
Collapsible dropdown component for grouping content.
Attributes:
header- text for the dropdown headeropened- whether the dropdown is initially openedhaptics- enable haptic feedback on toggle
Methods:
handleOpenClose()- toggle the dropdown open/closed state
Usage:
<d-dropdown header="dropdown example">
<div class="p-2">
<p>content goes here</p>
</div>
</d-dropdown>dIconButton
Attributes:
icon- font awesome icon classsize- font size of the iconcolor- icon coloractiveColor- active state colorloader- enable loading state capabilityloading- set initial loading state
Methods:
switchState(removeClass, addClass)- switch between icon stateschange(icon)- change the iconsetLoading(state)- set the loading state
Usage:
<d-icon-button icon="fa-solid fa-heart" loader></d-icon-button>dImageInput
Input component for selecting and previewing images.
Attributes:
accept- file types to accepticon- icon for the upload button
Methods:
reset()- clear the selected image
Events:
change- fired when an image is selected
Usage:
<d-image-input accept="image/png, image/jpeg"></d-image-input>dModal
Attributes:
opened- whether the modal is initially opened
Methods:
open()- open the modalclose()- close the modal
Usage:
<d-modal>
<div class="p-3">
<h3>modal title</h3>
<p>modal content goes here</p>
<d-button text="close"></d-button>
</div>
</d-modal>dNotification
Notification component for displaying alerts or messages.
Attributes:
opened- whether the notification is initially shown
Methods:
show()- display the notificationhide()- hide the notificationdestroy()- remove the notification from the DOM
Usage:
<d-notification>
<div class="p-2 bg-accent-1">
<h4>notification</h4>
<p>more content here</p>
</div>
</d-notification>dScroll
Custom scrolling container with a bouncing effect like on MacOS and iOS.
Attributes:
direction- scroll directionscrollbar-color- scrollbar colorscrollbar-hover-color- scrollbar hover colorthumb-width- width of the scrollbar thumbthumb-hover-width- width of the scrollbar thumb on hoverscrollbar-width- width of the scrollbar trackmargin-top- top margin for the scrollable contentmargin-bottom- bottom margin for the scrollable contentmargin-side- side margin for the scrollbar
Methods:
updateScrollbar()- update the scrollbar position and sizescrollTo(position)- scroll to a specific positionappend(element)- add an element to the scrollable content
Usage:
<d-scroll style="height: 300px;">
<div class="p-2">
<p>scrollable content goes here</p>
<!-- more content -->
</div>
</d-scroll>dSlider
Attributes:
min- minimum valuemax- maximum valuestep- step incrementvalue- initial valuethumbColor- thumb colorfillColor- fill colortrackColor- track colorsfx- enable sound effects on slide
Methods:
getValue()- get the current slider valuesetValue(value)- set the slider value
Events:
change- fired when slider value changes
Usage:
<d-slider min="0" max="100" step="1" value="50" id="volume"></d-slider>
<span data-slider-volume>50%</span>dTextInput
Text input component with optional icon.
Attributes:
placeholder- input placeholder texticon- icon to display inside the inputautocomplete- enable browser autocompletehaptics- enable haptic feedback on focuspassword- set input type to password
Methods:
getValue()- get the current input valuesetValue(value)- set the input value
Events:
change- fired when input value changeskeydown,keyup- keyboard eventsfocus,blur- focus events
Usage:
<d-text-input placeholder="search" icon="fa-solid fa-search"></d-text-input>dToggle
Toggle button group for selecting from multiple options.
Attributes:
color- button coloractiveColor- active button colortextColor- text colortextActiveColor- active text colorbgColor- background colorhaptics- 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
Usage:
<d-toggle>
<div toggle-default>option 1</div>
<div>option 2</div>
<div>option 3</div>
</d-toggle>dLoader
Simple loading spinner component.
Usage:
<d-loader></d-loader>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();Mongo DB API
dframework provides a MongoDB API wrapper for easy integration with MongoDB databases.
Features
- support for multiple environments (development and production)
- connection pooling and automatic reconnection
- comprehensive operations
- simple async/await API
Configuration
To connect to your MongoDB servers simply open the file /functions/lob/MongoAPI.js and change the following files in the constructor:
this.servers = {
dev: "", // mongo server URL
prod: "", // mongo server URL
};
this.dbName = ""; // your database nameYou can also add more URLs if you own more servers and want to quickly be able to switch between them.
Usage
// import the MongoDB API
const { MongoAPI } = require('../functions/lib/MongoAPI');
// initialize the API
const mongo = new MongoAPI();
// example operations
async function saveUser(user) {
await mongo.connect();
const result = await mongo.insertOne('users', user);
await mongo.destroy();
return result;
}
async function getUsers(query = {}) {
await mongo.connect();
const users = await mongo.find('users', query);
await mongo.destroy();
return users;
}Available methods
connect()- establish connection to MongoDBfind(collection, query, options)- find documents in collectionfindOne(collection, query, options)- find a single documentinsertOne(collection, document)- insert a documentinsertMany(collection, documents)- insert multiple documentsupdateOne(collection, filter, update, options)- update a documentupdateMany(collection, filter, update, options)- update multiple documentsdeleteOne(collection, filter, options)- delete a documentdeleteMany(collection, filter, options)- delete multiple documentsdestroy()- close connection
Contributing
Development setup
git clone https://github.com/dstrn825/dframework.git
cd dframework
npm installCoding standards
don't be an idiot
Pull request process
create a new branch for your feature:
git checkout -b feature/your-featuremake your changes and commit with descriptive messages
update doc if necessary
push your branch and create a PR
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/.
8 months ago