utilities
CSS Classes
Roseworx ships with a bunch of css helper classes so you can easily and consistently style your front end without writing extra css code. Here is a list of all the classes you can use;
Spacing
Type
Colors
Utilities
SCSS Mixins
Roseworx also ships with mixins which you can easily incorporate and use directly in your own SCSS files to inherit common and useful styles.
SCSS Variable Overrides
Roseworx has a bunch of configurable variables to tailor the framework to your own specific requirements.
Form Variables
Table Variables
Button Variables
Color Variables
Type Variables
Grid Variables
Spacing
Tabs
Sliders
Themes
To make things easier for consistent colors, the entire Roseworx framework core initially uses theme color variables. The following table shows which variables are initially set to which theme variables.
You can, of course, still override each of the above variables individually to something different, they do not have to be set to a theme variable.
Because you have to set these variables before importing the Roseworx scss, the Roseworx color scss variables will not be available so you will need to set it directly to a CSS color .
Instead of including all the JS helpers files individually (if you need to use all or the majority of them), you can import them all in one go.
import {rwxCanvas, rwxMath, rwxAnimate, rwxDOM, rwxMisc, rwxGeometry} from 'roseworx/js/helpers/rwxHelpers';HTML5 Canvas Helpers
import rwxCanvas from 'roseworx/js/helpers/rwxCanvasHelpers';Void
(
Canvas Node: HTMLElement
Canvas 2d Context: CanvasRenderingContext2D
Width: Number
Height: Number
)
Scales a canvas element to the specified width and height based on the users device pixel ratio so the user gets the best visual experience for the device they are viewing on.
const canvas = document.getElementById('demo');
const ctx = canvas.getContext('2d');
const width = 400;
const height = 400;
rwxCanvas.scale(canvas, ctx, width, height);
Void
(
Canvas 2d Context: CanvasRenderingContext2D
Sector Center Point: {x: Number , y: Number}
Sector Outer Radius: Number
Start Angle (in radians): Number
End Angle (in radians): Number
)
Draws a circle sector on the supplied canvas rendering context.
rwxCanvas.drawSector(ctx, {x:150, y:150}, 150, rwxGeometry.toRadians(270), rwxGeometry.toRadians(360));
Void
(
Canvas 2d Context: CanvasRenderingContext2D
Sector Center Point: {x: Number , y: Number}
Arc Outer Radius: Number
Arc Depth: Number
Start Angle (in radians): Number
End Angle (in radians): Number
)
Draws a circle arc on the supplied canvas rendering context.
rwxCanvas.drawArc(ctx, {x:150, y:150}, 150, 50, rwxGeometry.toRadians(180), rwxGeometry.toRadians(240));
Geometry Helpers
import rwxGeometry from 'roseworx/js/helpers/rwxGeometryHelpers';Number
(
Angle (in degrees): Number
)
Converts the specified angle in to radians.
const angle = 30;
const result = rwxGeometry.toRadians(angle);
Number
(
Start Point: {x: Number , y: Number}
Control Point: {x: Number , y: Number}
End Point: {x: Number , y: Number}
)
Returns an approximate (due to complexity) length of a quadratic bezier curve.
const start = {x: 50, y: 50};
const control = {x: 333, y: 33};
const end = {x: 250, y: 250};
const result = rwxGeometry.getQuadraticBezierLength(start, control, end);
Number
(
Point 1: {x: Number , y: Number}
Point 2: {x: Number , y: Number}
)
Returns a distance between 2 points.
const point1 = {x: 35, y: 35};
const point2 = {x: 265, y: 265};
const result = rwxGeometry.getDistance(point1, point2);
Boolean
(
Point: {x: Number , y: Number}
Circle Center Point: {x: Number , y: Number}
Radius: Number
)
Checks to see if a point is inside a circle of given centre point and radius.
const point = {x: 175, y: 175};
const circleCenter = {x: 150, y: 150};
const radius = 100;
const result = rwxGeometry.isInsideCircle(point, circleCenter, radius);
Boolean
(
Point: {x: Number , y: Number}
Sector Center Point: {x: Number , y: Number}
Radius: Number
Start Angle (in radians): Number
End Angle (in radians): Number
)
Checks to see if a point is inside a sector of a circle.
const point = {x: 200, y: 50};
const sectorCenter = {x: 150, y: 150};
const outerRadius = 150;
const startAngle = rwxGeometry.toRadians(270);
const endAngle = rwxGeometry.toRadians(360);
const result = rwxGeometry.isInsideSector(point, sectorCenter, outerRadius, startAngle, endAngle);
Boolean
(
Point: {x: Number , y: Number}
Arc Center Point: {x: Number , y: Number}
Outer Radius: Number
Inner Radius: Number
Start Angle (in radians): Number
End Angle (in radians): Number
)
Checks to see if a point is inside an arc of a circle.
const point = {x:50, y:100};
const arcCenter = {x:150, y:150};
const outerRadius = 150;
const innerRadius = 100;
const startAngle = rwxGeometry.toRadians(180);
const endAngle = rwxGeometry.toRadians(240);
const result = rwxGeometry.isInsideArc(point, arcCenter, outerRadius, innerRadius, startAngle, endAngle);
{x: Number, y: Number}
(
Point: {x: Number , y: Number}
Circle Center Point: {x: Number , y: Number}
Radius: Number
)
Finds the closest point on a circles circumference relative to a given point.
const point = {x:130, y:190};
const circleCenter {x:150, y:150};
const radius = 100;
const result = rwxGeometry.closestPointOnCircumference(point, circleCenter, radius);
Animate Helpers
Number
(
Start Value: Number
End Value: Number
ID: String
Easing Function: String
Duration: Number
Animation Complete Callback: Function
)
Animates a value from its start value to its end value over a specified duration and with the specified easing. If no duration is specified, 1000 (1 second) will be used. If no easing is specified, 'linear' will be used.
animate();
function animate()
{
let x = rwxAnimate.fromTo(40, 260, 'circle1x', 'easeInOutQuad', 2000, ()=>{console.log("done")});
let y = rwxAnimate.fromTo(40, 260, 'circle1y', 'easeInOutQuad', 2000);
window.requestAnimationFrame(animate);
}
For possible easing function values see easing functions.
fromTo method must be invoked from inside a requestAnimationFrame() loop. and the ID parameter must stay the same throughout the entirity of the animation for internal tracking purposes.
Number
(
Start Value: {x: Number , y: Number}
Control Value 1: {x: Number , y: Number}
Control Value 2: {x: Number , y: Number}
End Value: {x: Number , y: Number}
ID: String
Easing Function: String
Duration: Number
Animation Complete Callback: Function
)
Animates a value from its start value to its end value over a specified duration, with specified easing, VIA specified control points. If no duration is specified, 1000 (1 second) will be used. If no easing is specified, 'linear' will be used.
animate();
function animate()
{
let {x,y} = rwxAnimate.fromToBezier({x: 40, y:40}, {x: 70, y:300}, {x: 300, y:0}, {x: 260, y:260}, 'circleBezier', 'easeInOutQuint', 2000, ()=>{console.log("fromToBezier done")});
window.requestAnimationFrame(animate);
}
For possible easing function values see easing functions.
fromToBezier method must be invoked from inside a requestAnimationFrame() loop. The ID parameter must stay the same throughout the entirity of the animation for internal tracking purposes.
Easing Functions
Math Helpers
import rwxMath from 'roseworx/js/helpers/rwxMathHelpers';Number
(
From: Number
To: Number
)
Generates a random number inbetween the specified from and to (including both those numbers)
const result = rwxMath.randomInt(0,10);
Number
(
From: Number
To: Number
)
Generates a random float inbetween the specified from and to (including both those numbers)
const result = rwxMath.randomFloat(0,1);
DOM Helpers
import rwxDOM from 'roseworx/js/helpers/rwxDOMHelpers';Boolean
(
Element: HTML Element
Any Valid CSS Selector: String
)
Checks to see if the specified element has an ancestor (node above it in the DOM hierarchy) that matches the specified selector.
const element = document.getElementById('hasAncestorExample');
rwxDOM.hasAncestor(element, '.hasThisClass');
Void
(
Element: HTML Element
Duration (in seconds): Number
Callback: Function
)
Slides an element up to hide the contents inside. If callback is supplied, it will be ran after then animation has completed.
const element = document.getElementById('slideUpExample');
rwxDOM.slideUp(element, 1, ()=>{console.log("done");});
slideUp Demo
Press the below button to observe the slideUp action.Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
Void
(
Element: HTML Element
Duration (in seconds): Number
Callback: Function
)
Slides an element down to display the contents inside. If callback is supplied, it will be ran after then animation has completed. A class of .rwx-slide-expanded will be added to the element when it has expanded.
const element = document.getElementById('slideDownExample');
rwxDOM.slideDown(element, 1, ()=>{console.log("done");});
slideDown Demo
Press the below button to observe the slideDown action.Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
Void
(
Element: HTML Element
Duration (in seconds): Number
Callback: Function
)
Slides an element down if its contents is currently hidden, or up if its contents is visible. If callback is supplied, it will be ran after each slide animation. A class of .rwx-slide-expanded will be added to the element when it has expanded and removed when unexpanded.
const element = document.getElementById('slideToggleExample');
rwxDOM.slideToggle(element, 1, ()=>{console.log("done");});
slideToggle Demo
Press the below button to observe the slideToggle action.Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
Misc Helpers
import rwxMisc from 'roseworx/js/helpers/rwxMiscHelpers';String
Generates a random 10 character hexadecimal ID prefixed with an underscore.
const result = rwxMisc.uniqueId();
Object
(
Reference Object: Object
)
Safely clones an object, removing all references to the original object.
const obj = {a: "b", c: "d", e: "f"};
const result = rwxMisc.safeCloneObject(obj);
obj.a = "g";
Array
(
Reference Array: Array
)
Safely clones an array, removing all references to the original array.
const arr = ['a', 'b', 'c', 'd', 'e', 'f'];
const result = rwxMisc.safeCloneArray(arr);
arr[3] = "g";
Array
(
Reference Array: Array
)
Safely clones an array of objects, removing all references to the original array and all references to the objects inside.
const arr = [{a: "b"}, {c: "d"}, {e: "f"}];
const result = rwxMisc.safeCloneArrayOfObjects(arr);
arr[0] = {g: "h"};
arr[2].e = "i";
Void
(
Reference Array: Array
)
Randomly shuffles all the items in an array.
const arr = ['a', 'b', 'c', 'd', 'e', 'f'];
const result = rwxMisc.shuffleArray(arr);
Void
(
Cookie Name: String
Cookie Value: String
Expiry Length (in days): Number
)
Sets a cookie for the given amount of days. Omit the expiry length attribute to have the cookie expire at the end of the session.
const cookieName = "RoseWorx";
const cookieValue = "Is Great";
const expires = 31;
const result = rwxMisc.setCookie(cookieName, cookieValue, expires);
String
(
Cookie Name: String
)
Gets a cookie with the given cookie name.
const cookieName = "RoseWorx";
const result = rwxMisc.getCookie(cookieName);