@localnerve/sass-asset-functions 5.2.0 → 6.0.1
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/CHANGELOG.md +13 -0
- package/README.md +6 -0
- package/cjs/index.cjs +8 -48
- package/cjs/lib/legacyAPI.cjs +62 -0
- package/cjs/lib/modernAPIAsync.cjs +110 -0
- package/cjs/lib/modernAPISync.cjs +84 -0
- package/cjs/lib/processor.cjs +2 -2
- package/index.js +6 -48
- package/lib/legacyAPI.js +56 -0
- package/lib/modernAPIAsync.js +96 -0
- package/lib/modernAPISync.js +70 -0
- package/lib/processor.js +1 -1
- package/package.json +5 -5
- package/posttranspile.js +18 -14
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
# Sass Asset Functions Change Log
|
|
2
2
|
|
|
3
|
+
## 6.0.0
|
|
4
|
+
* sass 1.79.3
|
|
5
|
+
* BREAKING CHANGES:
|
|
6
|
+
* Default supports new JS API (synchronous dartSass.compile).
|
|
7
|
+
* Asynchronous modern JS API (dartSass.compileAsync) available via `async` option.
|
|
8
|
+
* Required if supplied function options (asset_host, asset_cache_buster, etc) are asynchronous AND/OR you are directly calling dartSass.compileAsync.
|
|
9
|
+
* Sass Legacy JS API, the default of this lib thru version sass-asset-functions@5, used by nodeSass/dartSass.render, available ONLY via `legacyAPI` option. This will be dropped at dart-sass@2.0.0.
|
|
10
|
+
* Dropped explicit support for old node-sass, although it still works thru node 20, for now.
|
|
11
|
+
* To get the old behavior, you have to supply `{ legacyAPI: true }` in the options.
|
|
12
|
+
|
|
13
|
+
## 5.2.1
|
|
14
|
+
* sass 1.79.2
|
|
15
|
+
|
|
3
16
|
## 5.2.0
|
|
4
17
|
* sass 1.79.0
|
|
5
18
|
|
package/README.md
CHANGED
|
@@ -21,6 +21,10 @@ _**NB** Please note that the `functions` option of dart-sass/node-sass is still
|
|
|
21
21
|
|
|
22
22
|
This module provides some of the asset functions that came with [Compass](http://compass-style.org). Originally a fork of [node-sass-asset-functions](https://github.com/fetch/node-sass-asset-functions) that was never merged.
|
|
23
23
|
|
|
24
|
+
## Release Notes
|
|
25
|
+
|
|
26
|
+
[Changelog](CHANGELOG.md)
|
|
27
|
+
|
|
24
28
|
## Functions Exposed to Sass
|
|
25
29
|
|
|
26
30
|
- `image-url($filename: null, $only_path: false)`
|
|
@@ -63,6 +67,8 @@ All options are optional.
|
|
|
63
67
|
| name | type | description |
|
|
64
68
|
| --- | --- | --- |
|
|
65
69
|
| `sass` | Object | A reference to an alternate Sass compiler to use other than dart-sass (must expose `types`). Defaults to `undefined` and a dart-sass reference is used |
|
|
70
|
+
| `legacyAPI` | Boolean | truthy to use the legacy sass API via the `render` function. Defaults to `false` |
|
|
71
|
+
| `async` | Boolean | truthy to use modern sass API via the `compileAsync` function. Required if supplied `asset_cache_buster` or `asset_host` function options are asynchronous. Defaults to `false` |
|
|
66
72
|
| `images_path` | String | The build-time file path to images. Defaults to `public/images` |
|
|
67
73
|
| `fonts_path` | String | The build-time file path to fonts. Defaults to `public/fonts` |
|
|
68
74
|
| `http_images_path` | String | The path to images as seen from the web (nothing to do with http). Defaults to `/images` |
|
package/cjs/index.cjs
CHANGED
|
@@ -6,6 +6,9 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.default = sassFunctions;
|
|
7
7
|
var defaultSass = _interopRequireWildcard(require("sass"));
|
|
8
8
|
var _processor = _interopRequireDefault(require("./lib/processor.cjs"));
|
|
9
|
+
var _legacyAPI = _interopRequireDefault(require("./lib/legacyAPI.cjs"));
|
|
10
|
+
var _modernAPISync = _interopRequireDefault(require("./lib/modernAPISync.cjs"));
|
|
11
|
+
var _modernAPIAsync = _interopRequireDefault(require("./lib/modernAPIAsync.cjs"));
|
|
9
12
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
10
13
|
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
11
14
|
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
@@ -18,54 +21,11 @@ function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e;
|
|
|
18
21
|
|
|
19
22
|
function sassFunctions(options = {}) {
|
|
20
23
|
const {
|
|
21
|
-
sass = defaultSass
|
|
24
|
+
sass = defaultSass,
|
|
25
|
+
legacyAPI = false,
|
|
26
|
+
async = false
|
|
22
27
|
} = options;
|
|
23
28
|
const processor = new _processor.default(options);
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
processor.image_url(filename.getValue(), url => {
|
|
27
|
-
if (!only_path.getValue()) url = `url('${url}')`;
|
|
28
|
-
done(new sass.types.String(url));
|
|
29
|
-
});
|
|
30
|
-
},
|
|
31
|
-
'inline-image($filename, $mime_type: null)': (filename, mime_type, done) => {
|
|
32
|
-
mime_type = mime_type instanceof sass.types.Null ? null : mime_type.getValue();
|
|
33
|
-
processor.inline_image(filename.getValue(), mime_type, dataUrl => {
|
|
34
|
-
done(new sass.types.String(`url('${dataUrl}')`));
|
|
35
|
-
});
|
|
36
|
-
},
|
|
37
|
-
'image-width($filename)': (filename, done) => {
|
|
38
|
-
processor.image_width(filename.getValue(), image_width => {
|
|
39
|
-
done(new sass.types.Number(image_width, 'px'));
|
|
40
|
-
});
|
|
41
|
-
},
|
|
42
|
-
'image-height($filename)': (filename, done) => {
|
|
43
|
-
processor.image_height(filename.getValue(), image_height => {
|
|
44
|
-
done(new sass.types.Number(image_height, 'px'));
|
|
45
|
-
});
|
|
46
|
-
},
|
|
47
|
-
'font-url($filename, $only-path: false)': (filename, only_path, done) => {
|
|
48
|
-
processor.font_url(filename.getValue(), url => {
|
|
49
|
-
if (!only_path.getValue()) url = `url('${url}')`;
|
|
50
|
-
done(new sass.types.String(url));
|
|
51
|
-
});
|
|
52
|
-
},
|
|
53
|
-
'font-files($filenames...)': (list, done) => {
|
|
54
|
-
let len = list.getLength(),
|
|
55
|
-
i = 0;
|
|
56
|
-
const filenames = [];
|
|
57
|
-
for (; i < len; ++i) {
|
|
58
|
-
filenames[i] = list.getValue(i).getValue();
|
|
59
|
-
}
|
|
60
|
-
processor.font_files(filenames, files => {
|
|
61
|
-
len = files.length;
|
|
62
|
-
i = 0;
|
|
63
|
-
list = new sass.types.List(len);
|
|
64
|
-
for (; i < len; ++i) {
|
|
65
|
-
list.setValue(i, new sass.types.String(`url('${files[i].url}') format('${files[i].type}')`));
|
|
66
|
-
}
|
|
67
|
-
done(list);
|
|
68
|
-
});
|
|
69
|
-
}
|
|
70
|
-
};
|
|
29
|
+
const modern = async ? _modernAPIAsync.default : _modernAPISync.default;
|
|
30
|
+
return legacyAPI ? (0, _legacyAPI.default)(sass, processor) : modern(sass, processor);
|
|
71
31
|
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = legacyAPI;
|
|
7
|
+
/**
|
|
8
|
+
* Custom Functions for sass Legacy JS API.
|
|
9
|
+
*
|
|
10
|
+
* Copyright (c) 2023-2024 Alex Grant (@localnerve), LocalNerve LLC
|
|
11
|
+
* Licensed under the MIT license.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
function legacyAPI(sass, processor) {
|
|
15
|
+
return {
|
|
16
|
+
'image-url($filename, $only_path: false)': (filename, only_path, done) => {
|
|
17
|
+
processor.image_url(filename.getValue(), url => {
|
|
18
|
+
if (!only_path.getValue()) url = `url('${url}')`;
|
|
19
|
+
done(new sass.types.String(url));
|
|
20
|
+
});
|
|
21
|
+
},
|
|
22
|
+
'inline-image($filename, $mime_type: null)': (filename, mime_type, done) => {
|
|
23
|
+
mime_type = mime_type instanceof sass.types.Null ? null : mime_type.getValue();
|
|
24
|
+
processor.inline_image(filename.getValue(), mime_type, dataUrl => {
|
|
25
|
+
done(new sass.types.String(`url('${dataUrl}')`));
|
|
26
|
+
});
|
|
27
|
+
},
|
|
28
|
+
'image-width($filename)': (filename, done) => {
|
|
29
|
+
processor.image_width(filename.getValue(), image_width => {
|
|
30
|
+
done(new sass.types.Number(image_width, 'px'));
|
|
31
|
+
});
|
|
32
|
+
},
|
|
33
|
+
'image-height($filename)': (filename, done) => {
|
|
34
|
+
processor.image_height(filename.getValue(), image_height => {
|
|
35
|
+
done(new sass.types.Number(image_height, 'px'));
|
|
36
|
+
});
|
|
37
|
+
},
|
|
38
|
+
'font-url($filename, $only-path: false)': (filename, only_path, done) => {
|
|
39
|
+
processor.font_url(filename.getValue(), url => {
|
|
40
|
+
if (!only_path.getValue()) url = `url('${url}')`;
|
|
41
|
+
done(new sass.types.String(url));
|
|
42
|
+
});
|
|
43
|
+
},
|
|
44
|
+
'font-files($filenames...)': (list, done) => {
|
|
45
|
+
let len = list.getLength(),
|
|
46
|
+
i = 0;
|
|
47
|
+
const filenames = [];
|
|
48
|
+
for (; i < len; ++i) {
|
|
49
|
+
filenames[i] = list.getValue(i).getValue();
|
|
50
|
+
}
|
|
51
|
+
processor.font_files(filenames, files => {
|
|
52
|
+
len = files.length;
|
|
53
|
+
i = 0;
|
|
54
|
+
list = new sass.types.List(len);
|
|
55
|
+
for (; i < len; ++i) {
|
|
56
|
+
list.setValue(i, new sass.types.String(`url('${files[i].url}') format('${files[i].type}')`));
|
|
57
|
+
}
|
|
58
|
+
done(list);
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = modernAPIAsync;
|
|
7
|
+
/**
|
|
8
|
+
* Custom Functions for asynchronous, sass modern JS API (compileAsync).
|
|
9
|
+
*
|
|
10
|
+
* Copyright (c) 2023-2024 Alex Grant (@localnerve), LocalNerve LLC
|
|
11
|
+
* Licensed under the MIT license.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
function modernAPIAsync(sass, processor) {
|
|
15
|
+
return {
|
|
16
|
+
'image-url($filename, $only_path: false)': args => {
|
|
17
|
+
return new Promise((resolve, reject) => {
|
|
18
|
+
try {
|
|
19
|
+
const filename = args[0].assertString('filename').text;
|
|
20
|
+
const only_path = args[1].assertBoolean('only_path').isTruthy;
|
|
21
|
+
processor.image_url(filename, url => {
|
|
22
|
+
if (!only_path) url = `url('${url}')`;
|
|
23
|
+
resolve(new sass.SassString(url, {
|
|
24
|
+
quotes: false
|
|
25
|
+
}));
|
|
26
|
+
});
|
|
27
|
+
} catch (err) {
|
|
28
|
+
reject(err);
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
},
|
|
32
|
+
'inline-image($filename, $mime_type: null)': args => {
|
|
33
|
+
return new Promise((resolve, reject) => {
|
|
34
|
+
try {
|
|
35
|
+
const filename = args[0].assertString('filename').text;
|
|
36
|
+
const mime_type = args[1].realNull === null ? null : args[1].assertString('mime_type').text;
|
|
37
|
+
processor.inline_image(filename, mime_type, dataUrl => {
|
|
38
|
+
resolve(new sass.SassString(`url('${dataUrl}')`, {
|
|
39
|
+
quotes: false
|
|
40
|
+
}));
|
|
41
|
+
});
|
|
42
|
+
} catch (err) {
|
|
43
|
+
reject(err);
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
},
|
|
47
|
+
'image-width($filename)': args => {
|
|
48
|
+
return new Promise((resolve, reject) => {
|
|
49
|
+
try {
|
|
50
|
+
const filename = args[0].assertString('filename').text;
|
|
51
|
+
processor.image_width(filename, image_width => {
|
|
52
|
+
resolve(new sass.SassNumber(image_width, 'px'));
|
|
53
|
+
});
|
|
54
|
+
} catch (err) {
|
|
55
|
+
reject(err);
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
},
|
|
59
|
+
'image-height($filename)': args => {
|
|
60
|
+
return new Promise((resolve, reject) => {
|
|
61
|
+
try {
|
|
62
|
+
const filename = args[0].assertString('filename').text;
|
|
63
|
+
processor.image_height(filename, image_height => {
|
|
64
|
+
resolve(new sass.SassNumber(image_height, 'px'));
|
|
65
|
+
});
|
|
66
|
+
} catch (err) {
|
|
67
|
+
reject(err);
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
},
|
|
71
|
+
'font-url($filename, $only-path: false)': args => {
|
|
72
|
+
return new Promise((resolve, reject) => {
|
|
73
|
+
try {
|
|
74
|
+
const filename = args[0].assertString('filename').text;
|
|
75
|
+
const only_path = args[1].assertBoolean('only_path').isTruthy;
|
|
76
|
+
processor.font_url(filename, url => {
|
|
77
|
+
if (!only_path) url = `url('${url}')`;
|
|
78
|
+
resolve(new sass.SassString(url, {
|
|
79
|
+
quotes: false
|
|
80
|
+
}));
|
|
81
|
+
});
|
|
82
|
+
} catch (err) {
|
|
83
|
+
reject(err);
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
},
|
|
87
|
+
'font-files($filenames...)': args => {
|
|
88
|
+
return new Promise((resolve, reject) => {
|
|
89
|
+
try {
|
|
90
|
+
const input = args[0].asList;
|
|
91
|
+
const filenames = [];
|
|
92
|
+
const result = [];
|
|
93
|
+
for (let i = 0; i < input.size; ++i) {
|
|
94
|
+
filenames[i] = input.get(i).assertString().text;
|
|
95
|
+
}
|
|
96
|
+
processor.font_files(filenames, files => {
|
|
97
|
+
for (let i = 0; i < files.length; ++i) {
|
|
98
|
+
result[i] = new sass.SassString(`url('${files[i].url}') format('${files[i].type}')`, {
|
|
99
|
+
quotes: false
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
resolve(new sass.SassList(result));
|
|
103
|
+
});
|
|
104
|
+
} catch (err) {
|
|
105
|
+
reject(err);
|
|
106
|
+
}
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
};
|
|
110
|
+
}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = modernAPISync;
|
|
7
|
+
/**
|
|
8
|
+
* Custom Functions for synchronous, sass modern JS API (compile).
|
|
9
|
+
*
|
|
10
|
+
* Copyright (c) 2023-2024 Alex Grant (@localnerve), LocalNerve LLC
|
|
11
|
+
* Licensed under the MIT license.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
function modernAPISync(sass, processor) {
|
|
15
|
+
return {
|
|
16
|
+
'image-url($filename, $only_path: false)': args => {
|
|
17
|
+
const filename = args[0].assertString('filename').text;
|
|
18
|
+
const only_path = args[1].assertBoolean('only_path').isTruthy;
|
|
19
|
+
let result = sass.sassNull;
|
|
20
|
+
processor.image_url(filename, url => {
|
|
21
|
+
if (!only_path) url = `url('${url}')`;
|
|
22
|
+
result = new sass.SassString(url, {
|
|
23
|
+
quotes: false
|
|
24
|
+
});
|
|
25
|
+
});
|
|
26
|
+
return result;
|
|
27
|
+
},
|
|
28
|
+
'inline-image($filename, $mime_type: null)': args => {
|
|
29
|
+
const filename = args[0].assertString('filename').text;
|
|
30
|
+
const mime_type = args[1].realNull === null ? null : args[1].assertString('mime_type').text;
|
|
31
|
+
let result = sass.sassNull;
|
|
32
|
+
processor.inline_image(filename, mime_type, dataUrl => {
|
|
33
|
+
result = new sass.SassString(`url('${dataUrl}')`, {
|
|
34
|
+
quotes: false
|
|
35
|
+
});
|
|
36
|
+
});
|
|
37
|
+
return result;
|
|
38
|
+
},
|
|
39
|
+
'image-width($filename)': args => {
|
|
40
|
+
const filename = args[0].assertString('filename').text;
|
|
41
|
+
let result = sass.sassNull;
|
|
42
|
+
processor.image_width(filename, image_width => {
|
|
43
|
+
result = new sass.SassNumber(image_width, 'px');
|
|
44
|
+
});
|
|
45
|
+
return result;
|
|
46
|
+
},
|
|
47
|
+
'image-height($filename)': args => {
|
|
48
|
+
const filename = args[0].assertString('filename').text;
|
|
49
|
+
let result = sass.sassNull;
|
|
50
|
+
processor.image_height(filename, image_height => {
|
|
51
|
+
result = new sass.SassNumber(image_height, 'px');
|
|
52
|
+
});
|
|
53
|
+
return result;
|
|
54
|
+
},
|
|
55
|
+
'font-url($filename, $only-path: false)': args => {
|
|
56
|
+
const filename = args[0].assertString('filename').text;
|
|
57
|
+
const only_path = args[1].assertBoolean('only_path').isTruthy;
|
|
58
|
+
let result = sass.sassNull;
|
|
59
|
+
processor.font_url(filename, url => {
|
|
60
|
+
if (!only_path) url = `url('${url}')`;
|
|
61
|
+
result = new sass.SassString(url, {
|
|
62
|
+
quotes: false
|
|
63
|
+
});
|
|
64
|
+
});
|
|
65
|
+
return result;
|
|
66
|
+
},
|
|
67
|
+
'font-files($filenames...)': args => {
|
|
68
|
+
const input = args[0].asList;
|
|
69
|
+
const filenames = [];
|
|
70
|
+
const result = [];
|
|
71
|
+
for (let i = 0; i < input.size; ++i) {
|
|
72
|
+
filenames[i] = input.get(i).assertString().text;
|
|
73
|
+
}
|
|
74
|
+
processor.font_files(filenames, files => {
|
|
75
|
+
for (let i = 0; i < files.length; ++i) {
|
|
76
|
+
result[i] = new sass.SassString(`url('${files[i].url}') format('${files[i].type}')`, {
|
|
77
|
+
quotes: false
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
return new sass.SassList(result);
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
}
|
package/cjs/lib/processor.cjs
CHANGED
|
@@ -36,7 +36,7 @@ const FONT_TYPES = {
|
|
|
36
36
|
eot: 'embedded-opentype'
|
|
37
37
|
};
|
|
38
38
|
class Processor {
|
|
39
|
-
constructor(options
|
|
39
|
+
constructor(options) {
|
|
40
40
|
this.options = options;
|
|
41
41
|
const {
|
|
42
42
|
images_path = defaultPaths.images_path,
|
|
@@ -178,4 +178,4 @@ class Processor {
|
|
|
178
178
|
}
|
|
179
179
|
}
|
|
180
180
|
}
|
|
181
|
-
exports.default = Processor;
|
|
181
|
+
exports.default = Processor;
|
package/index.js
CHANGED
|
@@ -6,56 +6,14 @@
|
|
|
6
6
|
*/
|
|
7
7
|
import * as defaultSass from 'sass';
|
|
8
8
|
import Processor from './lib/processor.js';
|
|
9
|
+
import legacy from './lib/legacyAPI.js';
|
|
10
|
+
import modernSync from './lib/modernAPISync.js';
|
|
11
|
+
import modernAsync from './lib/modernAPIAsync.js'
|
|
9
12
|
|
|
10
13
|
export default function sassFunctions (options = {}) {
|
|
11
|
-
const { sass = defaultSass } = options;
|
|
14
|
+
const { sass = defaultSass, legacyAPI = false, async = false } = options;
|
|
12
15
|
const processor = new Processor(options);
|
|
16
|
+
const modern = async ? modernAsync : modernSync;
|
|
13
17
|
|
|
14
|
-
return
|
|
15
|
-
'image-url($filename, $only_path: false)': (filename, only_path, done) => {
|
|
16
|
-
processor.image_url(filename.getValue(), (url) => {
|
|
17
|
-
if (!only_path.getValue()) url = `url('${url}')`;
|
|
18
|
-
done(new sass.types.String(url));
|
|
19
|
-
});
|
|
20
|
-
},
|
|
21
|
-
'inline-image($filename, $mime_type: null)': (filename, mime_type, done) => {
|
|
22
|
-
mime_type = mime_type instanceof sass.types.Null ? null : mime_type.getValue();
|
|
23
|
-
processor.inline_image(filename.getValue(), mime_type, (dataUrl) => {
|
|
24
|
-
done(new sass.types.String(`url('${dataUrl}')`));
|
|
25
|
-
});
|
|
26
|
-
},
|
|
27
|
-
'image-width($filename)': (filename, done) => {
|
|
28
|
-
processor.image_width(filename.getValue(), (image_width) => {
|
|
29
|
-
done(new sass.types.Number(image_width, 'px'));
|
|
30
|
-
});
|
|
31
|
-
},
|
|
32
|
-
'image-height($filename)': (filename, done) => {
|
|
33
|
-
processor.image_height(filename.getValue(), (image_height) => {
|
|
34
|
-
done(new sass.types.Number(image_height, 'px'));
|
|
35
|
-
});
|
|
36
|
-
},
|
|
37
|
-
'font-url($filename, $only-path: false)': (filename, only_path, done) => {
|
|
38
|
-
processor.font_url(filename.getValue(), (url) => {
|
|
39
|
-
if (!only_path.getValue()) url = `url('${url}')`;
|
|
40
|
-
done(new sass.types.String(url));
|
|
41
|
-
});
|
|
42
|
-
},
|
|
43
|
-
'font-files($filenames...)': (list, done) => {
|
|
44
|
-
let len = list.getLength(), i = 0;
|
|
45
|
-
const filenames = [];
|
|
46
|
-
for(; i < len; ++i) {
|
|
47
|
-
filenames[i] = list.getValue(i).getValue();
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
processor.font_files(filenames, (files) => {
|
|
51
|
-
len = files.length;
|
|
52
|
-
i = 0;
|
|
53
|
-
list = new sass.types.List(len);
|
|
54
|
-
for (; i < len; ++i) {
|
|
55
|
-
list.setValue(i, new sass.types.String(`url('${files[i].url}') format('${files[i].type}')`));
|
|
56
|
-
}
|
|
57
|
-
done(list);
|
|
58
|
-
});
|
|
59
|
-
}
|
|
60
|
-
};
|
|
18
|
+
return legacyAPI ? legacy(sass, processor) : modern(sass, processor);
|
|
61
19
|
}
|
package/lib/legacyAPI.js
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Custom Functions for sass Legacy JS API.
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) 2023-2024 Alex Grant (@localnerve), LocalNerve LLC
|
|
5
|
+
* Licensed under the MIT license.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
export default function legacyAPI (sass, processor) {
|
|
9
|
+
return {
|
|
10
|
+
'image-url($filename, $only_path: false)': (filename, only_path, done) => {
|
|
11
|
+
processor.image_url(filename.getValue(), url => {
|
|
12
|
+
if (!only_path.getValue()) url = `url('${url}')`;
|
|
13
|
+
done(new sass.types.String(url));
|
|
14
|
+
});
|
|
15
|
+
},
|
|
16
|
+
'inline-image($filename, $mime_type: null)': (filename, mime_type, done) => {
|
|
17
|
+
mime_type = mime_type instanceof sass.types.Null ? null : mime_type.getValue();
|
|
18
|
+
processor.inline_image(filename.getValue(), mime_type, dataUrl => {
|
|
19
|
+
done(new sass.types.String(`url('${dataUrl}')`));
|
|
20
|
+
});
|
|
21
|
+
},
|
|
22
|
+
'image-width($filename)': (filename, done) => {
|
|
23
|
+
processor.image_width(filename.getValue(), image_width => {
|
|
24
|
+
done(new sass.types.Number(image_width, 'px'));
|
|
25
|
+
});
|
|
26
|
+
},
|
|
27
|
+
'image-height($filename)': (filename, done) => {
|
|
28
|
+
processor.image_height(filename.getValue(), image_height => {
|
|
29
|
+
done(new sass.types.Number(image_height, 'px'));
|
|
30
|
+
});
|
|
31
|
+
},
|
|
32
|
+
'font-url($filename, $only-path: false)': (filename, only_path, done) => {
|
|
33
|
+
processor.font_url(filename.getValue(), url => {
|
|
34
|
+
if (!only_path.getValue()) url = `url('${url}')`;
|
|
35
|
+
done(new sass.types.String(url));
|
|
36
|
+
});
|
|
37
|
+
},
|
|
38
|
+
'font-files($filenames...)': (list, done) => {
|
|
39
|
+
let len = list.getLength(), i = 0;
|
|
40
|
+
const filenames = [];
|
|
41
|
+
for(; i < len; ++i) {
|
|
42
|
+
filenames[i] = list.getValue(i).getValue();
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
processor.font_files(filenames, files => {
|
|
46
|
+
len = files.length;
|
|
47
|
+
i = 0;
|
|
48
|
+
list = new sass.types.List(len);
|
|
49
|
+
for (; i < len; ++i) {
|
|
50
|
+
list.setValue(i, new sass.types.String(`url('${files[i].url}') format('${files[i].type}')`));
|
|
51
|
+
}
|
|
52
|
+
done(list);
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Custom Functions for asynchronous, sass modern JS API (compileAsync).
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) 2023-2024 Alex Grant (@localnerve), LocalNerve LLC
|
|
5
|
+
* Licensed under the MIT license.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
export default function modernAPIAsync (sass, processor) {
|
|
9
|
+
return {
|
|
10
|
+
'image-url($filename, $only_path: false)': args => {
|
|
11
|
+
return new Promise((resolve, reject) => {
|
|
12
|
+
try {
|
|
13
|
+
const filename = args[0].assertString('filename').text;
|
|
14
|
+
const only_path = args[1].assertBoolean('only_path').isTruthy;
|
|
15
|
+
processor.image_url(filename, url => {
|
|
16
|
+
if (!only_path) url = `url('${url}')`;
|
|
17
|
+
resolve(new sass.SassString(url, { quotes: false }));
|
|
18
|
+
});
|
|
19
|
+
} catch (err) {
|
|
20
|
+
reject(err);
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
},
|
|
24
|
+
'inline-image($filename, $mime_type: null)': args => {
|
|
25
|
+
return new Promise((resolve, reject) => {
|
|
26
|
+
try {
|
|
27
|
+
const filename = args[0].assertString('filename').text;
|
|
28
|
+
const mime_type = args[1].realNull === null ? null : args[1].assertString('mime_type').text;
|
|
29
|
+
processor.inline_image(filename, mime_type, dataUrl => {
|
|
30
|
+
resolve(new sass.SassString(`url('${dataUrl}')`, { quotes: false }));
|
|
31
|
+
});
|
|
32
|
+
} catch (err) {
|
|
33
|
+
reject(err);
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
},
|
|
37
|
+
'image-width($filename)': args => {
|
|
38
|
+
return new Promise((resolve, reject) => {
|
|
39
|
+
try {
|
|
40
|
+
const filename = args[0].assertString('filename').text;
|
|
41
|
+
processor.image_width(filename, image_width => {
|
|
42
|
+
resolve(new sass.SassNumber(image_width, 'px'));
|
|
43
|
+
});
|
|
44
|
+
} catch (err) {
|
|
45
|
+
reject(err);
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
},
|
|
49
|
+
'image-height($filename)': args => {
|
|
50
|
+
return new Promise((resolve, reject) => {
|
|
51
|
+
try {
|
|
52
|
+
const filename = args[0].assertString('filename').text;
|
|
53
|
+
processor.image_height(filename, image_height => {
|
|
54
|
+
resolve(new sass.SassNumber(image_height, 'px'));
|
|
55
|
+
});
|
|
56
|
+
} catch (err) {
|
|
57
|
+
reject(err);
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
},
|
|
61
|
+
'font-url($filename, $only-path: false)': args => {
|
|
62
|
+
return new Promise((resolve, reject) => {
|
|
63
|
+
try {
|
|
64
|
+
const filename = args[0].assertString('filename').text;
|
|
65
|
+
const only_path = args[1].assertBoolean('only_path').isTruthy;
|
|
66
|
+
processor.font_url(filename, url => {
|
|
67
|
+
if (!only_path) url = `url('${url}')`;
|
|
68
|
+
resolve(new sass.SassString(url, { quotes: false }));
|
|
69
|
+
});
|
|
70
|
+
} catch (err) {
|
|
71
|
+
reject(err);
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
},
|
|
75
|
+
'font-files($filenames...)': args => {
|
|
76
|
+
return new Promise((resolve, reject) => {
|
|
77
|
+
try {
|
|
78
|
+
const input = args[0].asList;
|
|
79
|
+
const filenames = [];
|
|
80
|
+
const result = [];
|
|
81
|
+
for(let i = 0; i < input.size; ++i) {
|
|
82
|
+
filenames[i] = input.get(i).assertString().text;
|
|
83
|
+
}
|
|
84
|
+
processor.font_files(filenames, files => {
|
|
85
|
+
for (let i = 0; i < files.length; ++i) {
|
|
86
|
+
result[i] = new sass.SassString(`url('${files[i].url}') format('${files[i].type}')`, { quotes: false });
|
|
87
|
+
}
|
|
88
|
+
resolve(new sass.SassList(result));
|
|
89
|
+
});
|
|
90
|
+
} catch (err) {
|
|
91
|
+
reject(err);
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Custom Functions for synchronous, sass modern JS API (compile).
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) 2023-2024 Alex Grant (@localnerve), LocalNerve LLC
|
|
5
|
+
* Licensed under the MIT license.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
export default function modernAPISync (sass, processor) {
|
|
9
|
+
return {
|
|
10
|
+
'image-url($filename, $only_path: false)': args => {
|
|
11
|
+
const filename = args[0].assertString('filename').text;
|
|
12
|
+
const only_path = args[1].assertBoolean('only_path').isTruthy;
|
|
13
|
+
let result = sass.sassNull;
|
|
14
|
+
processor.image_url(filename, url => {
|
|
15
|
+
if (!only_path) url = `url('${url}')`;
|
|
16
|
+
result = new sass.SassString(url, { quotes: false });
|
|
17
|
+
});
|
|
18
|
+
return result;
|
|
19
|
+
},
|
|
20
|
+
'inline-image($filename, $mime_type: null)': args => {
|
|
21
|
+
const filename = args[0].assertString('filename').text;
|
|
22
|
+
const mime_type = args[1].realNull === null ? null : args[1].assertString('mime_type').text;
|
|
23
|
+
let result = sass.sassNull;
|
|
24
|
+
processor.inline_image(filename, mime_type, dataUrl => {
|
|
25
|
+
result = new sass.SassString(`url('${dataUrl}')`, { quotes: false });
|
|
26
|
+
});
|
|
27
|
+
return result;
|
|
28
|
+
},
|
|
29
|
+
'image-width($filename)': args => {
|
|
30
|
+
const filename = args[0].assertString('filename').text;
|
|
31
|
+
let result = sass.sassNull;
|
|
32
|
+
processor.image_width(filename, image_width => {
|
|
33
|
+
result = new sass.SassNumber(image_width, 'px');
|
|
34
|
+
});
|
|
35
|
+
return result;
|
|
36
|
+
},
|
|
37
|
+
'image-height($filename)': args => {
|
|
38
|
+
const filename = args[0].assertString('filename').text;
|
|
39
|
+
let result = sass.sassNull;
|
|
40
|
+
processor.image_height(filename, image_height => {
|
|
41
|
+
result = new sass.SassNumber(image_height, 'px');
|
|
42
|
+
});
|
|
43
|
+
return result;
|
|
44
|
+
},
|
|
45
|
+
'font-url($filename, $only-path: false)': args => {
|
|
46
|
+
const filename = args[0].assertString('filename').text;
|
|
47
|
+
const only_path = args[1].assertBoolean('only_path').isTruthy;
|
|
48
|
+
let result = sass.sassNull;
|
|
49
|
+
processor.font_url(filename, url => {
|
|
50
|
+
if (!only_path) url = `url('${url}')`;
|
|
51
|
+
result = new sass.SassString(url, { quotes: false });
|
|
52
|
+
});
|
|
53
|
+
return result;
|
|
54
|
+
},
|
|
55
|
+
'font-files($filenames...)': args => {
|
|
56
|
+
const input = args[0].asList;
|
|
57
|
+
const filenames = [];
|
|
58
|
+
const result = [];
|
|
59
|
+
for(let i = 0; i < input.size; ++i) {
|
|
60
|
+
filenames[i] = input.get(i).assertString().text;
|
|
61
|
+
}
|
|
62
|
+
processor.font_files(filenames, files => {
|
|
63
|
+
for (let i = 0; i < files.length; ++i) {
|
|
64
|
+
result[i] = new sass.SassString(`url('${files[i].url}') format('${files[i].type}')`, { quotes: false });
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
return new sass.SassList(result);
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
}
|
package/lib/processor.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@localnerve/sass-asset-functions",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "6.0.1",
|
|
4
4
|
"description": "compass-style asset functions for dart-sass or other sass compilers",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"exports": {
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
"test": "npm run test-unit && npm run test-package",
|
|
17
17
|
"lint": "eslint .",
|
|
18
18
|
"pretranspile": "rimraf ./cjs",
|
|
19
|
-
"transpile": "babel index.js -o ./cjs/index.cjs && babel ./lib
|
|
19
|
+
"transpile": "babel index.js -o ./cjs/index.cjs && babel ./lib --out-dir ./cjs/lib",
|
|
20
20
|
"posttranspile": "node posttranspile.js",
|
|
21
21
|
"prepublishOnly": "npm run transpile"
|
|
22
22
|
},
|
|
@@ -52,13 +52,13 @@
|
|
|
52
52
|
"dependencies": {
|
|
53
53
|
"image-size": "^1.1.1",
|
|
54
54
|
"mime-types": "^2.1.35",
|
|
55
|
-
"sass": "^1.79.
|
|
55
|
+
"sass": "^1.79.3"
|
|
56
56
|
},
|
|
57
57
|
"devDependencies": {
|
|
58
58
|
"@babel/cli": "^7.25.6",
|
|
59
59
|
"@babel/preset-env": "^7.25.4",
|
|
60
|
-
"@eslint/js": "^9.
|
|
61
|
-
"eslint": "^9.
|
|
60
|
+
"@eslint/js": "^9.11.1",
|
|
61
|
+
"eslint": "^9.11.1",
|
|
62
62
|
"eslint-plugin-jest": "^28.8.3",
|
|
63
63
|
"glob": "^11.0.0",
|
|
64
64
|
"globals": "^15.9.0",
|
package/posttranspile.js
CHANGED
|
@@ -2,24 +2,28 @@ import fs from 'node:fs/promises';
|
|
|
2
2
|
import path from 'node:path';
|
|
3
3
|
|
|
4
4
|
async function processFile (filename) {
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
await fs.writeFile(
|
|
5
|
+
const newname = filename.replace(/\.js$/, '.cjs');
|
|
6
|
+
await fs.rename(filename, newname);
|
|
7
|
+
const data = await fs.readFile(newname, 'utf8');
|
|
8
|
+
const newData = data.replaceAll('.js")', '.cjs")');
|
|
9
|
+
await fs.writeFile(newname, newData);
|
|
10
10
|
}
|
|
11
11
|
|
|
12
12
|
async function processDirectory (dir) {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
const
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
13
|
+
try {
|
|
14
|
+
const files = await fs.readdir(dir);
|
|
15
|
+
for (const file of files) {
|
|
16
|
+
const name = `${dir}${path.sep}${file}`;
|
|
17
|
+
const stats = await fs.stat(name);
|
|
18
|
+
if (stats.isDirectory()) {
|
|
19
|
+
await processDirectory(name);
|
|
20
|
+
} else {
|
|
21
|
+
await processFile(name);
|
|
22
|
+
}
|
|
21
23
|
}
|
|
22
|
-
}
|
|
24
|
+
} catch (err) {
|
|
25
|
+
console.error('posttranspile error:\n\n', err);
|
|
26
|
+
}
|
|
23
27
|
}
|
|
24
28
|
|
|
25
29
|
await processDirectory('./cjs');
|