@cichol/sass-bridge 4.3.0 → 4.3.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/package.json +1 -1
- package/types/index.d.ts +13 -0
- package/types/type-converter.d.ts +3 -0
- package/types/types.d.ts +31 -0
- package/tests/artifacts/custom-function.ts +0 -18
- package/tests/artifacts/sqrt-cos.ts +0 -15
- package/tests/index.ts +0 -31
package/package.json
CHANGED
package/types/index.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import 'reflect-metadata';
|
|
2
|
+
import { CustomFunction } from 'sass';
|
|
3
|
+
import type { JavaScriptType } from './types';
|
|
4
|
+
export interface BridgedFunction {
|
|
5
|
+
execute(): JavaScriptType | Promise<JavaScriptType>;
|
|
6
|
+
}
|
|
7
|
+
export interface Constructor {
|
|
8
|
+
new (...args: JavaScriptType[]): BridgedFunction;
|
|
9
|
+
}
|
|
10
|
+
export declare function sassFunction(definition: string): ClassDecorator;
|
|
11
|
+
export declare function getFunctions(...moduleImports: Promise<{
|
|
12
|
+
default: Constructor;
|
|
13
|
+
}>[]): Promise<Record<string, CustomFunction<'async'>>>;
|
package/types/types.d.ts
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { Color } from 'chroma-js';
|
|
2
|
+
import * as sass from 'sass';
|
|
3
|
+
export type Primitives = boolean | number | string;
|
|
4
|
+
export type NumberWithUnit = {
|
|
5
|
+
value: number;
|
|
6
|
+
unit: string;
|
|
7
|
+
};
|
|
8
|
+
export type JavaScriptType<Base = Primitives | Color | NumberWithUnit | null> = Base | JavaScriptType<Base>[] | Map<JavaScriptType<Base>, JavaScriptType<Base>>;
|
|
9
|
+
type FilterSassPrefix<T extends string> = T extends `Sass${infer R}` ? R : never;
|
|
10
|
+
type SassTypes = Exclude<`Sass${FilterSassPrefix<keyof typeof sass>}`, `Sass${'Boolean' | 'Calculation'}`>;
|
|
11
|
+
declare const SassTypes: { [P in SassTypes]: (typeof sass)[P]; };
|
|
12
|
+
export declare const SassTRUE: sass.SassBoolean;
|
|
13
|
+
export type SassTRUE = typeof SassTRUE;
|
|
14
|
+
export declare const SassFALSE: sass.SassBoolean;
|
|
15
|
+
export type SassFALSE = typeof SassFALSE;
|
|
16
|
+
export declare const SassNULL: sass.Value;
|
|
17
|
+
export type SassNULL = typeof SassNULL;
|
|
18
|
+
export declare const SassNumber: typeof sass.SassNumber;
|
|
19
|
+
export type SassNumber = InstanceType<typeof SassNumber>;
|
|
20
|
+
export declare const SassString: typeof sass.SassString;
|
|
21
|
+
export type SassString = InstanceType<typeof SassString>;
|
|
22
|
+
export declare const SassColor: typeof sass.SassColor;
|
|
23
|
+
export type SassColor = InstanceType<typeof SassColor>;
|
|
24
|
+
export declare const SassList: typeof sass.SassList;
|
|
25
|
+
export type SassList = InstanceType<typeof SassList>;
|
|
26
|
+
export declare const SassMap: typeof sass.SassMap;
|
|
27
|
+
export type SassMap = InstanceType<typeof SassMap>;
|
|
28
|
+
export declare const SassBoolean: typeof sass.SassBoolean;
|
|
29
|
+
export type SassBoolean = sass.SassBoolean;
|
|
30
|
+
export type SassType = InstanceType<typeof SassTypes extends Record<any, infer R> ? R : never> | SassBoolean;
|
|
31
|
+
export {};
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import type { BridgedFunction } from '../../types';
|
|
2
|
-
import { sassFunction } from '../../releases/esm.js'; // eslint-disable-line import/extensions
|
|
3
|
-
|
|
4
|
-
@sassFunction('custom-function($a, $b)')
|
|
5
|
-
export default class CustomFunction implements BridgedFunction {
|
|
6
|
-
#a: string;
|
|
7
|
-
|
|
8
|
-
#b: string;
|
|
9
|
-
|
|
10
|
-
public constructor(A: string, B: string) {
|
|
11
|
-
this.#a = A;
|
|
12
|
-
this.#b = B;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
public async execute() {
|
|
16
|
-
return this.#a.toLowerCase() + this.#b.toUpperCase();
|
|
17
|
-
}
|
|
18
|
-
}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import type { BridgedFunction } from '../../types';
|
|
2
|
-
import { sassFunction } from '../../releases/esm.js'; // eslint-disable-line import/extensions
|
|
3
|
-
|
|
4
|
-
@sassFunction('sqrt-cos($x)')
|
|
5
|
-
export default class SquareRootCosine implements BridgedFunction {
|
|
6
|
-
#x: number;
|
|
7
|
-
|
|
8
|
-
public constructor(X: number) {
|
|
9
|
-
this.#x = X;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
public async execute() {
|
|
13
|
-
return Math.sqrt(Math.cos(this.#x));
|
|
14
|
-
}
|
|
15
|
-
}
|
package/tests/index.ts
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
// eslint-disable-next-line eslint-comments/disable-enable-pair
|
|
2
|
-
/* eslint-disable import/extensions */
|
|
3
|
-
|
|
4
|
-
// Third-party modules.
|
|
5
|
-
import { describe, it } from 'mocha';
|
|
6
|
-
import { expect } from 'chai';
|
|
7
|
-
import * as sass from 'sass';
|
|
8
|
-
|
|
9
|
-
// Testing target.
|
|
10
|
-
import { getFunctions } from '../releases/esm.js';
|
|
11
|
-
|
|
12
|
-
describe('@cichol/sass-bridge', () => {
|
|
13
|
-
it('should be working properly', async () => {
|
|
14
|
-
const source = `
|
|
15
|
-
body > *:first-child:after {
|
|
16
|
-
content: custom-function('HELLO', 'world');
|
|
17
|
-
line-height: sqrt-cos(${2 * Math.PI});
|
|
18
|
-
}
|
|
19
|
-
`;
|
|
20
|
-
|
|
21
|
-
const functions = await getFunctions(
|
|
22
|
-
import('./artifacts/custom-function.ts'),
|
|
23
|
-
import('./artifacts/sqrt-cos.ts')
|
|
24
|
-
);
|
|
25
|
-
|
|
26
|
-
const { css: result } = await sass.compileStringAsync(source, { functions });
|
|
27
|
-
|
|
28
|
-
expect(result).to.includes('content: "helloWORLD";');
|
|
29
|
-
expect(result).to.includes('line-height: 1;');
|
|
30
|
-
});
|
|
31
|
-
});
|