gerillass 1.3.3 → 1.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -23,11 +23,14 @@ Hope you’ll enjoy using it!
23
23
 
24
24
  - [Dart Sass Upgrade](#dart-sass-upgrade)
25
25
  - [Installation](#installation)
26
- - [Node.js Installation](#nodejs-installation)
27
- - [Using with React.js](#using-with-reactjs)
26
+ - [Using with Vite](#using-with-vite)
27
+ - [Using with webpack](#using-with-webpack)
28
+ - [Using with Next.js](#using-with-nextjs)
29
+ - [Using with Angular](#using-with-angular)
28
30
  - [Using with Gulp](#using-with-gulp)
29
31
  - [Using with Grunt](#using-with-grunt)
30
32
  - [Cloning the Repository from Github](#cloning-the-repository-from-github)
33
+ - [Versions these examples were tested with](#versions-these-examples-were-tested-with)
31
34
  - [Namespace Usage](#namespace-usage)
32
35
  - [Vendor Prefix Support](#vendor-prefix-support)
33
36
  - [Experimenting](#experimenting)
@@ -45,74 +48,118 @@ Because LibSass and the packages built on it, including Node Sass, are deprecate
45
48
 
46
49
  npm install gerillass --save-dev
47
50
 
48
- You can **import** Gerillass with **node_modules** path.
51
+ Or with Yarn:
49
52
 
50
- @import '{node_modules_path}/gerillass/scss/gerillass';
53
+ yarn add gerillass --dev
51
54
 
52
- **To add the library without using the {node_modules_path} see the examples below.**
55
+ Then load it. If your setup resolves packages from **node_modules** Vite, webpack, Next.js and most modern bundlers do this is all you need:
53
56
 
54
- If you're working with an **eyeglass** setup, simply import it without providing the **node_modules** path.
57
+ @use 'gerillass' as *;
55
58
 
56
- @import 'gerillass';
59
+ If you call Dart Sass yourself rather than through a bundler, turn on its package importer and use a `pkg:` URL:
57
60
 
58
- ### Node.js Installation
61
+ @use 'pkg:gerillass' as *;
59
62
 
60
- If you are working on a Node project you can add Gerillass as a dependency.
63
+ ```js
64
+ // Dart Sass 1.71.0 or later
65
+ import * as sass from 'sass';
66
+ import { NodePackageImporter } from 'sass';
61
67
 
62
- #### npm installation
68
+ sass.compile('style.scss', { importers: [new NodePackageImporter()] });
69
+ ```
63
70
 
64
- npm install gerillass --save-dev
71
+ Or from the command line:
72
+
73
+ sass --pkg-importer=node style.scss style.css
74
+
75
+ Pointing straight at the file always works too:
76
+
77
+ @use '{node_modules_path}/gerillass/scss/gerillass' as *;
78
+
79
+ The per-tool recipes below were each verified against a real build of Gerillass v1.5.0. The versions used are listed at the end of this section.
80
+
81
+ > **A note on eyeglass.** Gerillass still ships eyeglass module metadata, but eyeglass has not been released since June 2022 and its importer is broken with current Dart Sass — any `@import` fails with `doneImporting is not a function`, whether Gerillass is involved or not. It also relies on the legacy JS API, which Dart Sass removes in 2.0.0. Use the `pkg:` importer above instead; it is the built-in equivalent.
82
+
83
+ ### Using with Vite
84
+
85
+ Vite resolves the package by name, so there is nothing to configure. This covers anything built on Vite, including React, Vue, Svelte, SvelteKit and Astro.
86
+
87
+ @use 'gerillass' as *;
88
+
89
+ ### Using with webpack
90
+
91
+ `sass-loader` also resolves the package by name, with no extra options.
92
+
93
+ @use 'gerillass' as *;
94
+
95
+ ### Using with Next.js
96
+
97
+ Next.js needs to be told where the library lives. In `next.config.mjs`:
98
+
99
+ export default {
100
+ sassOptions: {
101
+ loadPaths: ["node_modules/gerillass/scss"],
102
+ },
103
+ };
65
104
 
66
- #### Yarn installation
105
+ Then, in any `.scss` file:
67
106
 
68
- yarn add gerillass
107
+ @use 'gerillass' as *;
69
108
 
70
- ### Using with React.js
109
+ ### Using with Angular
71
110
 
72
- Simply `@import` the library at the beginning of your App.scss file without using the **node_modules** path.
111
+ Add the library folder to the build target's options in `angular.json`. Angular calls this option `includePaths`, not `loadPaths`:
73
112
 
74
- @import 'gerillass';
113
+ "stylePreprocessorOptions": {
114
+ "includePaths": ["node_modules/gerillass/scss"]
115
+ }
116
+
117
+ Then, in `src/styles.scss`:
118
+
119
+ @use 'gerillass' as *;
75
120
 
76
121
  ### Using with Gulp
77
122
 
78
- You can add a new Gulp task as in the below example or simply add `includePath: ['node_modules/gerillass/scss']` option to the task if you have one already.
79
-
80
- function sassify(done) {
81
- return (
82
- src("assets/sass/**/*.scss")
83
- .pipe(sass({
84
- outputStyle: "expanded",
85
- includePaths: ["node_modules/gerillass/scss"],
86
- }).on('error', sass.logError))
87
- .pipe(dest("assets/css"))
88
- );
89
- done()
123
+ `gulp-sass` hands its options straight to Dart Sass, so the option is **`loadPaths`**. The old `includePaths` name came from Node Sass and no longer resolves.
124
+
125
+ const { src, dest } = require("gulp");
126
+ const sass = require("gulp-sass")(require("sass"));
127
+
128
+ function styles() {
129
+ return src("assets/sass/**/*.scss")
130
+ .pipe(sass({ loadPaths: ["node_modules/gerillass/scss"] }).on("error", sass.logError))
131
+ .pipe(dest("assets/css"));
90
132
  }
91
133
 
92
- Including to the project:
93
-
94
- @import 'gerillass';
134
+ exports.styles = styles;
95
135
 
96
- ### Using with Grunt
136
+ Then:
97
137
 
98
- You can add the Gerillass library by editing your Gruntfile.js at the root level of your project. Simply find the sass related rules and add `loadPath: ['node_modules/gerillass/scss']` inside the `options` object.
138
+ @use 'gerillass' as *;
99
139
 
100
- sass: {
101
- dist: {
102
- options: {
103
- style: "expanded",
104
- loadPath: ['node_modules/gerillass/scss']
140
+ ### Using with Grunt
141
+
142
+ Use `grunt-sass` with Dart Sass as the implementation. The option here is **`loadPaths`** as well — not `loadPath`, and not `includePaths`.
143
+
144
+ module.exports = function (grunt) {
145
+ grunt.loadNpmTasks("grunt-sass");
146
+ grunt.initConfig({
147
+ sass: {
148
+ dist: {
149
+ options: {
150
+ implementation: require("sass"),
151
+ loadPaths: ["node_modules/gerillass/scss"],
152
+ },
153
+ files: { "css/main.css": "src/main.scss" },
154
+ },
105
155
  },
106
- files: {
107
- "main.css": "main.scss"
108
- }
109
- }
110
- }
156
+ });
157
+ };
158
+
159
+ Then:
160
+
161
+ @use 'gerillass' as *;
111
162
 
112
- Including to the project:
113
-
114
- @import 'gerillass';
115
-
116
163
  ### Cloning the repository from Github
117
164
 
118
165
  You can clone the repository into your local computer from Github.
@@ -125,7 +172,19 @@ Or you can add the library as a submodule into your Git based project ([What is
125
172
 
126
173
  Including to the project:
127
174
 
128
- @import '{folder_path}/gerillass/scss/gerillass';
175
+ @use '{folder_path}/gerillass/scss/gerillass' as *;
176
+
177
+ ### Versions these examples were tested with
178
+
179
+ | Tool | Version |
180
+ |---|---|
181
+ | Dart Sass | 1.103.1 |
182
+ | Vite | 8.2.2 |
183
+ | webpack / sass-loader | 5.110.3 / 17.0.1 |
184
+ | Next.js | 16.3.4 |
185
+ | Angular CLI | 20.3.36 |
186
+ | Gulp / gulp-sass | 5.0.1 / 6.0.1 |
187
+ | Grunt / grunt-sass | 1.6.3 / 4.1.0 |
129
188
 
130
189
  ## Namespace Usage
131
190
 
package/package.json CHANGED
@@ -5,8 +5,18 @@
5
5
  "homepage": "https://gerillass.com",
6
6
  "author": "Halil İbrahim Çakıroğlu",
7
7
  "main": "scss/_gerillass.scss",
8
+ "exports": {
9
+ ".": {
10
+ "sass": "./scss/_gerillass.scss",
11
+ "default": "./scss/_gerillass.scss"
12
+ },
13
+ "./*": {
14
+ "sass": "./*",
15
+ "default": "./*"
16
+ }
17
+ },
8
18
  "license": "Apache-2.0",
9
- "version": "1.3.3",
19
+ "version": "1.5.0",
10
20
  "repository": {
11
21
  "type": "git",
12
22
  "url": "git+https://github.com/selfishprimate/gerillass.git"
@@ -961,27 +961,7 @@
961
961
  &::before {
962
962
  content: "";
963
963
  display: block;
964
- @if not $ratio {
965
- padding-top: 56.25%;
966
- } @else if $ratio {
967
- @if type-of($ratio) == string {
968
- $width: null;
969
- $height: null;
970
- @if str-index($ratio, "/") {
971
- $fslash-index: str-index($ratio, "/");
972
- $width: __convertToNumber(str-slice($ratio, 1, $fslash-index - 1));
973
- $height: __convertToNumber(str-slice($ratio, $fslash-index + 1));
974
- } @else if str-index($ratio, ":") {
975
- $colon-index: str-index($ratio, ":");
976
- $width: __convertToNumber(str-slice($ratio, 1, $colon-index - 1));
977
- $height: __convertToNumber(str-slice($ratio, $colon-index + 1));
978
- }
979
- $calc: math.div($height, $width) * 100;
980
- padding-top: #{$calc * 1%};
981
- } @else if type-of($ratio) == number {
982
- padding-top: math.div(1, $ratio) * 100%;
983
- }
984
- }
964
+ padding-top: __validateRatio($ratio);
985
965
  }
986
966
  & > * {
987
967
  width: 100%;
@@ -1115,27 +1095,7 @@
1115
1095
  &::before {
1116
1096
  content: "";
1117
1097
  display: block;
1118
- @if not $ratio {
1119
- padding-top: 56.25%;
1120
- } @else if $ratio {
1121
- @if type-of($ratio) == string {
1122
- $width: null;
1123
- $height: null;
1124
- @if str-index($ratio, "/") {
1125
- $fslash-index: str-index($ratio, "/");
1126
- $width: __convertToNumber(str-slice($ratio, 1, $fslash-index - 1));
1127
- $height: __convertToNumber(str-slice($ratio, $fslash-index + 1));
1128
- } @else if str-index($ratio, ":") {
1129
- $colon-index: str-index($ratio, ":");
1130
- $width: __convertToNumber(str-slice($ratio, 1, $colon-index - 1));
1131
- $height: __convertToNumber(str-slice($ratio, $colon-index + 1));
1132
- }
1133
- $calc: math.div($height, $width) * 100;
1134
- padding-top: #{$calc * 1%};
1135
- } @else if type-of($ratio) == number {
1136
- padding-top: math.div(1, $ratio) * 100%;
1137
- }
1138
- }
1098
+ padding-top: __validateRatio($ratio);
1139
1099
  }
1140
1100
  & > * {
1141
1101
  width: 100%;
@@ -38,6 +38,7 @@
38
38
  @import "utilities/shorthand-property";
39
39
  @import "utilities/validate-breakpoint";
40
40
  @import "utilities/validate-length";
41
+ @import "utilities/validate-ratio";
41
42
  @import "utilities/validate-scissors";
42
43
 
43
44
  @import "library/adaptive";
@@ -5,27 +5,7 @@
5
5
  &::before {
6
6
  content: "";
7
7
  display: block;
8
- @if not $ratio {
9
- padding-top: 56.25%;
10
- } @else if $ratio {
11
- @if type-of($ratio) == string {
12
- $width: null;
13
- $height: null;
14
- @if str-index($ratio, "/") {
15
- $fslash-index: str-index($ratio, "/");
16
- $width: __convertToNumber(str-slice($ratio, 1, $fslash-index - 1));
17
- $height: __convertToNumber(str-slice($ratio, $fslash-index + 1));
18
- } @else if str-index($ratio, ":") {
19
- $colon-index: str-index($ratio, ":");
20
- $width: __convertToNumber(str-slice($ratio, 1, $colon-index - 1));
21
- $height: __convertToNumber(str-slice($ratio, $colon-index + 1));
22
- }
23
- $calc: math.div($height, $width) * 100;
24
- padding-top: #{$calc * 1%};
25
- } @else if type-of($ratio) == number {
26
- padding-top: math.div(1, $ratio) * 100%;
27
- }
28
- }
8
+ padding-top: __validateRatio($ratio);
29
9
  }
30
10
  & > * {
31
11
  width: 100%;
@@ -5,27 +5,7 @@
5
5
  &::before {
6
6
  content: "";
7
7
  display: block;
8
- @if not $ratio {
9
- padding-top: 56.25%;
10
- } @else if $ratio {
11
- @if type-of($ratio) == string {
12
- $width: null;
13
- $height: null;
14
- @if str-index($ratio, "/") {
15
- $fslash-index: str-index($ratio, "/");
16
- $width: __convertToNumber(str-slice($ratio, 1, $fslash-index - 1));
17
- $height: __convertToNumber(str-slice($ratio, $fslash-index + 1));
18
- } @else if str-index($ratio, ":") {
19
- $colon-index: str-index($ratio, ":");
20
- $width: __convertToNumber(str-slice($ratio, 1, $colon-index - 1));
21
- $height: __convertToNumber(str-slice($ratio, $colon-index + 1));
22
- }
23
- $calc: math.div($height, $width) * 100;
24
- padding-top: #{$calc * 1%};
25
- } @else if type-of($ratio) == number {
26
- padding-top: math.div(1, $ratio) * 100%;
27
- }
28
- }
8
+ padding-top: __validateRatio($ratio);
29
9
  }
30
10
  & > * {
31
11
  width: 100%;
@@ -0,0 +1,42 @@
1
+ @charset "UTF-8";
2
+
3
+ @function __validateRatio($ratio) {
4
+ // No argument at all keeps the 16/9 default.
5
+ @if $ratio == null {
6
+ @return 56.25%;
7
+ }
8
+
9
+ @if type-of($ratio) == "number" {
10
+ @if not unitless($ratio) {
11
+ @error "`#{$ratio}` is not a valid ratio. A numeric ratio must be unitless, like `1.77`.";
12
+ }
13
+ @if $ratio <= 0 {
14
+ @error "`#{$ratio}` is not a valid ratio. A numeric ratio must be greater than zero.";
15
+ }
16
+ @return math.div(1, $ratio) * 100%;
17
+ }
18
+
19
+ @if type-of($ratio) == "string" {
20
+ $separator: null;
21
+ @if str-index($ratio, "/") {
22
+ $separator: str-index($ratio, "/");
23
+ } @else if str-index($ratio, ":") {
24
+ $separator: str-index($ratio, ":");
25
+ } @else {
26
+ @error "`#{$ratio}` is not a valid ratio. A string ratio must separate width and height with `/` or `:`, like `\"16/9\"` or `\"16:9\"`.";
27
+ }
28
+
29
+ $width: __convertToNumber(str-slice($ratio, 1, $separator - 1));
30
+ $height: __convertToNumber(str-slice($ratio, $separator + 1));
31
+
32
+ @if $width == 0 {
33
+ @error "`#{$ratio}` is not a valid ratio. The width must be greater than zero.";
34
+ }
35
+ @return math.div($height, $width) * 100%;
36
+ }
37
+
38
+ // Anything else -- most commonly a list, which is what `16/9` becomes once
39
+ // Dart Sass 2.0.0 removes slash division. Without this the mixin would emit
40
+ // no padding-top at all and silently produce a ratio box with no ratio.
41
+ @error "`#{$ratio}` is not a valid ratio. Pass a string like `\"16/9\"` or `\"16:9\"`, a unitless number like `1.77`, or no argument at all for the 16/9 default. You passed a #{type-of($ratio)}.";
42
+ }