dframework is a lightweight JavaScript framework for building modern web applications with minimal configuration.
npm install -g @dstrn825/dframework
To create a new project:
dstrn init
cd my-project
dstrn config
dstrn serve
Creates a new project:
dstrn init
After initialization, you can configure your project using the dstrn config
command.
Configure project settings:
dstrn config
Start a development server:
dstrn serve
The server is accessible at http://localhost:8250
.
Build for production:
dstrn build
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.
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
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
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
Create a new script:
dstrn create script
Scripts can be included in all pages, specific pages, or none.
Create a new page:
dstrn create page
Pages can be automatically wired up to the routing system if enabled.
Create a new style:
dstrn create style
Stylesheets can be bundled together for optimized delivery or kept separate.
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.
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 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
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.
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 |
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
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.
.dark-theme
, .light-theme
--base
, --container-1
through --container-4
--accent-1
through --accent-3
, --inactive-accent
--link-color
, --binary-color
, --primary-text
, --secondary-text
, --indicator-text
.d-none
, .d-block
,
.d-inline
, .d-inline-block
,
.d-grid
, .d-contents
.d-table
,
.d-table-cell
,
.d-table-row
.flex-row
, .flex-column
,
.flex-center
.flex-1
, .flex-0
,
.flex-wrap
, .flex-grow
.justify-between
, .justify-around
,
.justify-evenly
, .justify-center
,
.justify-start
, .justify-end
.align-between
, .align-around
,
.align-evenly
, .align-center
,
.align-start
, .align-end
.g-0
through .g-5
(in 1em increments)
.relative
, .absolute
,
.fixed
, .sticky
.absolute-center
, .absolute-fill
.top-0
, .right-0
,
.bottom-0
, .left-0
.translateX
, .translateY
.w-5
through .w-100
(in 5% increments),
.w-100vw
.w-auto
, .w-fit
,
.w-min
, .w-max
,
.w-fill
.min-w-*
, .max-w-*
(same increments as width)
.h-5
through .h-100
(in 5% increments),
.h-100svh
.h-auto
, .h-fit
,
.h-min
, .h-max
,
.h-fill
.min-h-*
, .max-h-*
(same increments as height)
.p-0
, .p-05
,
.p-1
, .p-2
,
.p-3
, .p-4
,
.p-5
(in 1em increments)
.py-*
, .px-*
(in 1em increments)
.pt-*
(top), .pb-*
(bottom),
.pl-*
(left), .pr-*
(right)
.m-0
, .m-05
,
.m-1
, .m-2
,
.m-3
, .m-4
,
.m-5
, .m-auto
(in 1em increments)
.my-*
, .mx-*
(including
.mx-auto
for centering)
.mt-*
(top), .mb-*
(bottom),
.ml-*
(left), .mr-*
(right)
.fs-05
through .fs-10
.text-center
.bold
, .thin
.text-vertical
.overflow-ellipsis
dframework provides a set of utility functions to simplify common JavaScript operations:
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 elementsaddClass(element, className)
- add a CSS classremoveClass(element, className)
- remove a CSS classtoggleClass(element, className)
- toggle a CSS classmove(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 forEachisUndefined(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)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 objectsformatDate(value)
- formats any date or date string into a readable formatlocalizeDate(value)
- converts any date or date string into the local timezonedframework provides several custom HTML components. These components offer reusable UI elements with consistent styling and behavior.
Button component with icon support.
text
- button texticon
- FontAwesome 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 statesetDisabled(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 colortype
- checkbox style (1
: toggle switch, 2
: checkmark box, default: 1
)text
- checkbox textactiveColor
- active state colortextColor
- label text colorinactiveColor
- inactive state colorsetText(text)
- change the checkbox textsetActiveColor(color)
- change the active state colorsetInactiveColor(color)
- change the inactive state colorsetTextColor(color)
- change the label text colorchange
- fired when checkbox state changesname
- 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 selectionset(value)
- set the color valueget()
- get the current color valuecolorchange
- fired when color value changesCombobox component with optional input support.
options
- JSON string of options array with format [{value: "value1", text: "text 1"}, ...]
allowInput
- allow text input in the dropdownhaptics
- enable haptic feedback on selectionsetOptions(options)
- update the available optionsset(value)
- set the selected valueget()
- get the currently selected valuechange
- fired when selection changesContext menu component that appears on right-click.
openCloseMenu(event)
- open or close the context menuopenMenu()
- open the context menucloseMenu()
- close the context menuclick
- fired when a context menu item is clickedthis is the drawer content
Slide-out drawer component for additional content or navigation.
direction
- direction from which the drawer appears ("top", "right", "bottom", "left", default: "right")opened
- whether the drawer is initially openedhandleOpenClose()
- toggle the drawer open/closed statethis is the dropdown content
Collapsible dropdown component for grouping content.
header
- text for the dropdown headeropened
- whether the dropdown is initially openedhaptics
- enable haptic feedback on togglehandleOpenClose()
- toggle the dropdown open/closed stateicon
- font awesome icon classsize
- font size of the iconcolor
- icon coloractiveColor
- active state colorloader
- enable loading state capabilityloading
- set initial loading stateswitchState(removeClass, addClass)
- switch between icon stateschange(icon)
- change the iconsetLoading(state)
- set the loading stateInput component for selecting and previewing images.
accept
- file types to accepticon
- icon for the upload buttonreset()
- clear the selected imagechange
- fired when an image is selectedModal component for displaying content in a pop-up overlay.
opened
- whether the modal is initially openedopen()
- open the modalclose()
- close the modalNotification component for displaying alerts or messages.
opened
- whether the notification is initially shownshow()
- display the notificationhide()
- hide the notificationdestroy()
- remove the notification from the DOMCustom scrolling container with a bouncing effect like on MacOS and iOS.
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 scrollbarupdateScrollbar()
- update the scrollbar position and sizescrollTo(position)
- scroll to a specific positionappend(element)
- add an element to the scrollable contentSlider component for selecting a value within a range.
min
- minimum valuemax
- maximum valuestep
- step incrementvalue
- initial valuethumbColor
- thumb colorfillColor
- fill colortrackColor
- track colorsfx
- enable sound effects on slidegetValue()
- get the current slider valuesetValue(value)
- set the slider valuechange
- fired when slider value changesText input component with optional icon.
placeholder
- input placeholder texticon
- icon to display inside the inputautocomplete
- enable browser autocompletehaptics
- enable haptic feedback on focuspassword
- set input type to passwordgetValue()
- get the current input valuesetValue(value)
- set the input valuechange
- fired when input value changeskeydown
, keyup
- keyboard eventsfocus
, blur
- focus eventsToggle button group for selecting from multiple options.
color
- button coloractiveColor
- active button colortextColor
- text colortextActiveColor
- active text colorbgColor
- background colorhaptics
- enable haptic feedback on toggleset(toggle)
- set the active toggle (by index or element)get()
- get the currently active toggle elementchange
- fired when selection changesSimple loading spinner component.
dframework includes a built-in routing system for creating single-page applications with client-side navigation.
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.
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();
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