Artifex is a simple project boilerplate using artifex-core
Either clone the repo or download the zip.
Install dependencies
npm install
Start the webpack dev server
npm run serve
A simple way to execute javascript based on the route. Artifex uses Navigo.
You'll see in source/scripts/app.js
an example route is already set up:
const router = new Navigo('/');
router.on({
'/': () => import('./pages/Home'),
}).resolve();
The page module Home
is the entry point for that page for both the JavaScript and CSS.
import createRouteHandler from '@artifexweb/core/scripts/createRouteHandler';
import './index.scss';
export default createRouteHandler(async () => {
//
});
The createRouteHandler
function is a simple function that returns a compatible route object for Navigo:
export default (uses, hooks = {}, name = undefined) => {
const route = {
uses,
};
if (Object.keys(hooks).length) {
route.hooks = hooks;
}
if (name) {
route.as = name;
}
return route;
};
A full example might be:
createRouteHandler(() => {
// inital functionality, the main route handler
}, {
before: (done, match) => {
// The `before` hook receives two arguments. The first one is a function that
// needs to be called with either no arguments or `false`. The no-argument
// version means "move forward". `false` stops the resolving
// and your handler will not be called.
},
after: (match) => {
// `after` is called after your handler
},
leave: (done, match) => {
// `leave` is called when you are about to leave out of the route. Similarly to the `before`
// hook accepts a function as first argument and a match object as second. If the function
// is called with `false` Navigo will stop resolving the new matched
// route meaning "we cant' go out of the current route".
},
already: (match) => {
// `already` is called when this is the current route and it matches again
},
}, 'this.is.just.a.name');
Retrieve the current location's path segments as an array or individual segment by index
Retrieve information about current location or parse a provided URL
===================
Attach events to matching breakpoint rules
Syncing media queries and JavaScript reliably can be tedious. Wee seamlessly combines and triggers breakpoint logic based on your configured project media queries.
You can easily disable any unneeded breakpoints by setting them to false in wee.json or add more by adding a breakpoint value to this same array.
- Portrait Mobile (320px)
- Landscape Mobile (480px)
- Portrait Tablet (768px)
- Desktop 1 (1024px)
- Desktop 2 (1280px)
- Desktop 3 (1440px)
Wee uses the font family of the HTML element to reference the current breakpoint. For example, the Portrait Mobile breakpoint is triggered when the font family is '2'. When you add/remove default breakpoints, the corresponding font family values will update automatically when the build process is run.
Default Values
- Portrait Mobile (320px) - font-family: 1
- Landscape Mobile (480px) - font-family: 2
- Portrait Tablet (768px) - font-family: 3
- Desktop 1 (1024px) - font-family: 4
- Desktop 2 (1280px) - font-family: 5
- Desktop 3 (1440px) - font-family: 6
Customized Values
- Portrait Mobile (320px) - font-family: 1
- Landscape Mobile (480px) - font-family: 2
- Portrait Tablet (768px) - font-family: 3
- Landscape Tablet (900px) - font-family: 4
- Desktop 1 (1024px) - font-family: 5
- Desktop 2 (1280px) - font-family: 6
- Desktop 3 (1440px) - font-family: 7
- Desktop 4 (1600px) - font-family: 8
Watch single or set of screen events with specified options
Variable | Type | Default | Description | Required |
---|---|---|---|---|
sets | object, array | - | Object parameters below | ✔ |
Variable | Type | Default | Description | Required |
---|---|---|---|---|
args | array | - | Callback arguments | - |
callback | function | - | Matching callback | ✔ |
each | boolean | false | Execute callback for each matching breakpoint | - |
init | boolean | true | Immediately evaluate breakpoint logic | - |
max | number | - | Maximum breakpoint value | - |
min | number | - | Minimum breakpoint value | - |
namespace | string | - | Event namespace for granular resetting | - |
once | boolean | false | Disable callback after first execution | - |
scope | object | - | Callback scope | - |
size | number | - | Specific breakpoint value | - |
watch | boolean | true | Evaluate on screen resize | - |
You can setup as many breakpoint sets as you need. They are added to a global window resize event that evaluates once against all stored rules.
import screen from '@artifexweb/core/scripts/screen'
screen.map({
size: 4,
callback(obj) {
console.log(obj);
},
});
An object with the direction, size, previous size, and init status is passed as the first callback argument.
Variable | Type | Default | Description | Required |
---|---|---|---|---|
dir | number | - | 1 if sized up, 0 if sized down | - |
init | boolean | - | true if run initially, else false | - |
prev | number | - | 1-6 representing previous value | - |
size | number | - | 1-6 representing current value | - |
import screen from '@artifexweb/core/scripts/screen'
import common from './common';
screen.map([
{
size: 1,
callback: [
common.mobile,
common.smallScreen,
],
},
{
min: 3,
max: 4,
watch: false,
callback: common.tablet,
},
{
min: 5,
args: ['passThrough'],
callback(obj, val) {
console.log(val); // passThroughconsole.log(obj);
},
},
]);
Reset all bound events
Variable | Type | Default | Description | Required |
---|---|---|---|---|
namespace | string | - | Namespace of events to reset | - |
import screen from '@artifexweb/core/scripts/screen'
screen.reset();
Evaluate the current breakpoint
Variable | Type | Default | Description | Required |
---|---|---|---|---|
namespace | string | - | Evaluate mappings registered under specific namespace | - |
import screen from '@artifexweb/core/scripts/screen'
screen.run();
import screen from '@artifexweb/core/scripts/screen'
$screen.run('namespace');
Get current screen value
The value is determined by the value of the HTML element font family which stores the current media query number. The response falls between 1 and 6.
import screen from '@artifexweb/core/scripts/screen'
screen.size();