1
0
mirror of https://github.com/locomotivemtl/locomotive-boilerplate.git synced 2026-01-15 00:55:08 +08:00

18 Commits

Author SHA1 Message Date
Lucas Bigot
65a265c0ea Merge branch 'master' into feature/css-reset 2024-03-26 15:02:21 -04:00
Lucas Bigot
afb3a4aa6a Merge pull request #161 from locomotivemtl/feature/svgs-folder
Add dedicated SVG sprite folder
2024-03-26 14:56:03 -04:00
Lucas Bigot
40521c3f2b Merge pull request #169 from locomotivemtl/feature/config-spacing
Rework spacing css config
2024-03-26 14:47:00 -04:00
Lucas Bigot
81d47b88b8 Rename spacer by spacings 2024-03-26 14:06:25 -04:00
Lucas Bigot
c16407c8c1 Add clamp-with-max & size-clamp sass functions 2024-03-26 11:41:23 -04:00
Lucas Bigot
522c9c0bcb Replace vh based spacing values 2024-03-26 11:16:54 -04:00
Chauncey McAskill
ddd12ffc38 Fix inconsistent argument name in grid-space() function in Sass 2024-01-29 15:19:09 -05:00
Chauncey McAskill
9e6d7ae182 Replace deprecated divisions in Sass 2024-01-29 15:17:50 -05:00
Chauncey McAskill
d5bff3ab50 Remove obsolete span() function in Sass 2024-01-29 15:06:58 -05:00
Chauncey McAskill
962ba66b96 Update NPM dependencies
Updated:
- autoprefixer v10.4.13 → v10.4.17
- esbuild v0.17.6 → →0.20.0
- locomotive-scroll v5.0.0-beta.9 → v5.0.0-beta.11
- sass v1.69.5 → v1.70.0
2024-01-29 12:30:58 -05:00
Chauncey McAskill
5b6bca6ce3 Replace deprecated division in '_widths.scss' 2024-01-29 11:37:39 -05:00
Chauncey McAskill
4ae90a5821 Annotate Sass modules section of 'main.scss' 2024-01-29 11:37:18 -05:00
Lucas
31061daf60 Merge pull request #166 from locomotivemtl/feature/viewport-units
Viewport sizes fallbacks
2024-01-22 16:31:21 +01:00
Lucas
ceefeb554e Merge branch 'master' into feature/viewport-units 2024-01-22 16:31:12 +01:00
Lucas Vallenet
276b5eebc0 Update asset version 2024-01-22 16:30:40 +01:00
Jérémy Minié
a37c5b047a Fix PurgeCSS safelist regex 2024-01-16 15:07:09 -05:00
Lucas Vallenet
3f7077b488 Add vh/svh/dvh/lvh fallbacks 2024-01-11 11:45:46 +01:00
Lucas Vallenet
7021666c46 Add dedicated svg folder 2023-12-11 11:43:16 +01:00
20 changed files with 542 additions and 388 deletions

View File

@@ -1,3 +1,3 @@
{
"version": 1705057647819
"version": 1711479720413
}

View File

@@ -1,25 +1,66 @@
import modular from 'modujs';
import * as modules from './modules';
import globals from './globals';
import { debounce } from './utils/tickers'
import { debounce } from './utils/tickers';
import { $html } from './utils/dom';
import { ENV, FONT, CUSTOM_EVENT, CSS_CLASS } from './config'
import { isFontLoadingAPIAvailable, loadFonts } from './utils/fonts';
const app = new modular({
modules: modules,
modules,
});
window.addEventListener('load', (event) => {
const setViewportSizes = () => {
// Document styles
const documentStyles = document.documentElement.style;
// Viewport width
const vw = document.body.clientWidth * 0.01;
documentStyles.setProperty('--vw', `${vw}px`);
// Return if browser supports vh, svh, dvh, & lvh
if (ENV.SUPPORTS_VH) {
return
}
// Viewport height
const height = window.innerHeight;
const svh = document.documentElement.clientHeight * 0.01;
documentStyles.setProperty('--svh', `${svh}px`);
const dvh = height * 0.01;
documentStyles.setProperty('--dvh', `${dvh}px`);
if (document.body) {
const fixed = document.createElement('div');
fixed.style.width = '1px';
fixed.style.height = '100vh';
fixed.style.position = 'fixed';
fixed.style.left = '0';
fixed.style.top = '0';
fixed.style.bottom = '0';
fixed.style.visibility = 'hidden';
document.body.appendChild(fixed);
var fixedHeight = fixed.clientHeight;
fixed.remove();
const lvh = fixedHeight * 0.01;
documentStyles.setProperty('--lvh', `${lvh}px`);
}
}
window.addEventListener('load', () => {
const $style = document.getElementById('main-css');
if ($style) {
if ($style.isLoaded) {
init();
} else {
$style.addEventListener('load', (event) => {
init();
});
$style.addEventListener('load', init);
}
} else {
console.warn('The "main-css" stylesheet not found');
@@ -28,6 +69,7 @@ window.addEventListener('load', (event) => {
function init() {
globals();
setViewportSizes();
app.init(app);
@@ -36,14 +78,18 @@ function init() {
$html.classList.remove(CSS_CLASS.LOADING);
// Bind window resize event with default vars
const resizeEndEvent = new CustomEvent(CUSTOM_EVENT.RESIZE_END)
const resizeEndEvent = new CustomEvent(CUSTOM_EVENT.RESIZE_END);
window.addEventListener('resize', () => {
$html.style.setProperty('--vw', `${document.documentElement.clientWidth * 0.01}px`)
setViewportSizes();
debounce(() => {
window.dispatchEvent(resizeEndEvent)
window.dispatchEvent(resizeEndEvent);
}, 200, false)
})
window.addEventListener('orientationchange', () => {
setViewportSizes();
})
/**
* Eagerly load the following fonts.
*/
@@ -53,12 +99,12 @@ function init() {
if (ENV.IS_DEV) {
console.group('Eager fonts loaded!', eagerFonts.length, '/', document.fonts.size);
console.group('State of eager fonts:')
eagerFonts.forEach((font) => console.log(font.family, font.style, font.weight, font.status/*, font*/))
console.groupEnd()
console.group('State of all fonts:')
document.fonts.forEach((font) => console.log(font.family, font.style, font.weight, font.status/*, font*/))
console.groupEnd()
console.group('State of eager fonts:');
eagerFonts.forEach(font => console.log(font.family, font.style, font.weight, font.status));
console.groupEnd();
console.group('State of all fonts:');
document.fonts.forEach(font => console.log(font.family, font.style, font.weight, font.status));
console.groupEnd();
}
});
}

View File

@@ -21,6 +21,15 @@ const ENV = Object.freeze({
// Device
IS_MOBILE,
IS_DESKTOP: !IS_MOBILE,
// Supports
SUPPORTS_VH: (
'CSS' in window
&& 'supports' in window.CSS
&& window.CSS.supports('height: 100svh')
&& window.CSS.supports('height: 100dvh')
&& window.CSS.supports('height: 100lvh')
)
})
// Main CSS classes used within the project

View File

@@ -1,9 +1,12 @@
// ==========================================================================
// Main
// ==========================================================================
// Modules
// ==========================================================================
@use "sass:math";
// ==========================================================================
// Tools
// ==========================================================================
@@ -17,14 +20,14 @@
// Settings
// ==========================================================================
@import "settings/config";
@import "settings/config.breakpoints";
@import "settings/config.colors";
@import "settings/config.eases";
@import "settings/config.fonts";
@import "settings/config.spacers";
@import "settings/config.spacings";
@import "settings/config.timings";
@import "settings/config.zindexes";
@import "settings/config";
@import "settings/config.variables";
// Vendors

View File

@@ -48,7 +48,7 @@
// // Logo
// .svg-logo {
// --icon-width: #{rem(100px)};
// --icon-ratio: 20/30; // width/height based on svg viewBox
// --icon-ratio: math.div(20, 30); // width/height based on svg viewBox
// // Sizes
// .o-icon.-big & {

View File

@@ -32,12 +32,13 @@ $easing: ease("power2.out");
// Spacing Units
// =============================================================================
$unit: 60px;
$unit-small: 20px;
$unit: 60px;
$unit-small: 20px;
$vw-viewport: 1440;
// Container
// ==========================================================================
$padding: $unit;
$padding: $unit;
// Grid
// ==========================================================================

View File

@@ -1,40 +0,0 @@
// ==========================================================================
// Settings / Config / Spacers
// ==========================================================================
// Spacers
// ==========================================================================
$spacers: (
'gutter': var(--grid-gutter),
'xs': #{vh(5)},
'sm': #{vh(7.5)},
'md': #{vh(10)},
'lg': #{vh(12.5)},
'xl': #{vh(15)},
);
// Function
// ==========================================================================
// Returns spacer.
//
// ```scss
// .c-box {
// margin-top: spacer(gutter);
// }
// ```
//
// @param {string} $key - The spacer key in $spacers.
// @param {number} $multiplier - The multiplier of the spacer value.
// @return {size}
@function spacer($spacer: $spacer-default, $multiplier: 1) {
@if not map-has-key($spacers, $spacer) {
@error "Unknown master spacer: #{$spacer}";
}
$index: map-get($spacers, $spacer);
@return calc(#{$index} * #{$multiplier});
}

View File

@@ -0,0 +1,69 @@
// ==========================================================================
// Settings / Config / Spacings
// ==========================================================================
:root {
--spacing-2xs-mobile: 6;
--spacing-2xs-desktop: 10;
--spacing-xs-mobile: 12;
--spacing-xs-desktop: 16;
--spacing-sm-mobile: 22;
--spacing-sm-desktop: 32;
--spacing-md-mobile: 32;
--spacing-md-desktop: 56;
--spacing-lg-mobile: 48;
--spacing-lg-desktop: 96;
--spacing-xl-mobile: 64;
--spacing-xl-desktop: 128;
--spacing-2xl-mobile: 88;
--spacing-2xl-desktop: 176;
--spacing-3xl-mobile: 122;
--spacing-3xl-desktop: 224;
}
// Spacings
// ==========================================================================
$spacings: (
'gutter': var(--grid-gutter),
'2xs': #{size-clamp('2xs')},
'xs': #{size-clamp('xs')},
'sm': #{size-clamp('sm')},
'md': #{size-clamp('md')},
'lg': #{size-clamp('lg')},
'xl': #{size-clamp('xl')},
'2xl': #{size-clamp('2xl')},
'3xl': #{size-clamp('3xl')},
);
// Function
// ==========================================================================
// Returns spacing.
//
// ```scss
// .c-box {
// margin-top: spacing(gutter);
// }
// ```
//
// @param {string} $key - The spacing key in $spacings.
// @param {number} $multiplier - The multiplier of the spacing value.
// @return {size}
@function spacing($spacing: 'sm', $multiplier: 1) {
@if not map-has-key($spacings, $spacing) {
@error "Unknown master spacing: #{$spacing}";
}
$index: map-get($spacings, $spacing);
@return calc(#{$index} * #{$multiplier});
}

View File

@@ -48,17 +48,6 @@
@return math.div($size, $base) * 1rem;
}
// Converts a number to a percentage.
//
// @alias percentage()
// @link http://sassdoc.com/annotations/#alias
// @param {Number} $number - The value to convert.
// @return {Number} A percentage.
@function span($number) {
@return percentage($number);
}
// Checks if a list contains a value(s).
//
// @link https://github.com/thoughtbot/bourbon/blob/master/core/bourbon/validators/_contains.scss
@@ -120,30 +109,58 @@ $context: 'frontend' !default;
//
// ```scss
// .c-box {
// width: grid-space(6/12);
// margin-left: grid-space(1/12, 1);
// }
// ```
//
// @param {number} $number - The percentage spacer
// @param {number} $inset - The grid gutter inset
// @return {function<number>}
@function grid-space($percentage, $inset: 0) {
@return calc(#{$percentage} * (100vw - 2 * var(--grid-margin, 0px)) - (1 - #{$percentage}) * var(--grid-gutter, 0px) + #{$inset} * var(--grid-gutter, 0px));
}
// Returns calculation of a percentage of the viewport height.
//
// ```scss
// .c-box {
// height: vh(100);
// width: grid-space(math.div(6, 12));
// margin-left: grid-space(math.div(1, 12), 1);
// }
// ```
//
// @param {number} $number - The percentage number
// @return {function<number>} in vh
@function vh($number) {
@return calc(#{$number} * var(--vh, 1vh));
// @param {number} $inset - The grid gutter inset
// @return {function<number>}
@function grid-space($number, $inset: 0) {
@return calc(#{$number} * (100vw - 2 * var(--grid-margin, 0px)) - (1 - #{$number}) * var(--grid-gutter, 0px) + #{$inset} * var(--grid-gutter, 0px));
}
// Returns calculation of a percentage of the viewport small height.
//
// ```scss
// .c-box {
// height: svh(100);
// }
// ```
//
// @param {number} $number - The percentage number
// @return {function<number>} in svh
@function svh($number) {
@return calc(#{$number} * var(--svh, 1svh));
}
// Returns calculation of a percentage of the viewport large height.
//
// ```scss
// .c-box {
// height: lvh(100);
// }
// ```
//
// @param {number} $number - The percentage number
// @return {function<number>} in lvh
@function lvh($number) {
@return calc(#{$number} * var(--lvh, 1lvh));
}
// Returns calculation of a percentage of the viewport dynamic height.
//
// ```scss
// .c-box {
// height: dvh(100);
// }
// ```
//
// @param {number} $number - The percentage number
// @return {function<number>} in dvh
@function dvh($number) {
@return calc(#{$number} * var(--dvh, 1dvh));
}
// Returns calculation of a percentage of the viewport width.
@@ -161,6 +178,19 @@ $context: 'frontend' !default;
@return calc(#{$number} * var(--vw, 1vw));
}
@function clamp-with-max($min, $size, $max) {
$vw-context: $vw-viewport * 0.01;
@return clamp(#{$min}, calc(#{$size} / #{$vw-context} * 1vw), #{$max});
}
@function size-clamp($size) {
@return clamp-with-max(
calc(#{rem(1px)} * var(--spacing-#{$size}-mobile)),
var(--spacing-#{$size}-desktop),
calc(#{rem(1px)} * var(--spacing-#{$size}-desktop))
);
}
// Returns clamp of calculated preferred responsive font size
// within a font size and breakpoint range.
//

View File

@@ -8,12 +8,11 @@
///
/// @example
/// .u-margin-top {}
/// .u-padding-left-large {}
/// .u-margin-right-small {}
/// .u-margin-top-xs {}
/// .u-padding-left-lg {}
/// .u-margin-right-sm {}
/// .u-padding {}
/// .u-padding-right-none {}
/// .u-padding-horizontal {}
/// .u-padding-vertical-small {}
///
/// @link https://github.com/inuitcss/inuitcss/blob/512977a/utilities/_utilities.spacing.scss
////
@@ -35,7 +34,7 @@ $spacing-properties: (
'margin': 'margin',
) !default;
$spacing-sizes: join($spacers, (
$spacing-sizes: join($spacings, (
null: var(--grid-gutter),
'none': 0
));
@@ -51,7 +50,7 @@ $spacing-sizes: join($spacers, (
// Base class
$base-class: ".u-" + #{$property-namespace}#{$direction-namespace}#{$size-namespace};
// Spacer without media query
// Spacing without media query
@if $breakpoint == "tiny" {
#{$base-class} {
@each $direction in $directions {
@@ -60,7 +59,7 @@ $spacing-sizes: join($spacers, (
}
}
// Spacer min-width breakpoints `@from-*`
// Spacing min-width breakpoints `@from-*`
#{$base-class}\@from-#{$breakpoint} {
@media #{mq-min($breakpoint)} {
@each $direction in $directions {
@@ -69,7 +68,7 @@ $spacing-sizes: join($spacers, (
}
}
// Spacer max-width breakpoints @to-*`
// Spacing max-width breakpoints @to-*`
#{$base-class}\@to-#{$breakpoint} {
@media #{mq-max($breakpoint)} {
@each $direction in $directions {

View File

@@ -23,6 +23,6 @@ $widths-fractions: 1 2 3 4 5 !default;
.u-1\/2\@from-small {
@media (min-width: $from-small) {
width: span(1/2);
width: 50%;
}
}

View File

@@ -236,7 +236,7 @@ async function purgeUnusedCSS(outfile, label) {
keyframes: true,
safelist: {
// Keep all except .u-gc-* | .u-margin-* | .u-padding-*
standard: [ /^(((?!\bu-gc-).)*$ | (((?!\bu-margin-).)*$) | (((?!\bu-padding-).)*$))/ ]
standard: [ /^(?!.*\b(u-gc-|u-margin|u-padding)).*$/ ]
},
variables: true,
})

View File

@@ -15,7 +15,7 @@
"dest": "./www/assets/scripts"
},
"svgs": {
"src": "./assets/images/sprite",
"src": "./assets/svgs",
"dest": "./www/assets/images"
},
"views": {

577
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -14,21 +14,21 @@
"build": "node --experimental-json-modules --no-warnings build/build.js"
},
"dependencies": {
"locomotive-scroll": "^5.0.0-beta.9",
"locomotive-scroll": "^5.0.0-beta.11",
"modujs": "^1.4.2",
"modularload": "^1.2.6",
"svg4everybody": "^2.1.9"
},
"devDependencies": {
"autoprefixer": "^10.4.13",
"autoprefixer": "^10.4.17",
"browser-sync": "^3.0.2",
"concat": "^1.0.3",
"esbuild": "^0.17.6",
"esbuild": "^0.20.0",
"kleur": "^4.1.5",
"node-notifier": "^10.0.1",
"postcss": "^8.4.21",
"purgecss": "^5.0.0",
"sass": "^1.69.5",
"sass": "^1.70.0",
"svg-mixer": "~2.3.14",
"tiny-glob": "^0.2.9"
},

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long