css-calipers 0.8.0 β 0.9.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/README.md +29 -1
- package/dist/cjs/index.js +1 -0
- package/dist/cjs/libraryHelpers/vanilla-extract.js +7 -0
- package/dist/cjs/mediaQueries/factory.js +162 -0
- package/dist/cjs/mediaQueries/index.js +2 -0
- package/dist/cjs/mediaQueries/linting.js +1 -1
- package/dist/cjs/mediaQueries/mediaQueries.js +3 -2
- package/dist/cjs/mediaQueries/moduleRegistry.js +5 -0
- package/dist/esm/index.d.ts +1 -0
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +1 -0
- package/dist/esm/libraryHelpers/vanilla-extract.d.ts +3 -0
- package/dist/esm/libraryHelpers/vanilla-extract.d.ts.map +1 -0
- package/dist/esm/libraryHelpers/vanilla-extract.js +3 -0
- package/dist/esm/mediaQueries/factory.d.ts +29 -0
- package/dist/esm/mediaQueries/factory.d.ts.map +1 -0
- package/dist/esm/mediaQueries/factory.js +158 -0
- package/dist/esm/mediaQueries/index.d.ts +2 -0
- package/dist/esm/mediaQueries/index.d.ts.map +1 -1
- package/dist/esm/mediaQueries/index.js +2 -0
- package/dist/esm/mediaQueries/linting.js +1 -1
- package/dist/esm/mediaQueries/mediaQueries.d.ts +2 -0
- package/dist/esm/mediaQueries/mediaQueries.d.ts.map +1 -1
- package/dist/esm/mediaQueries/mediaQueries.js +1 -1
- package/dist/esm/mediaQueries/moduleRegistry.d.ts +27 -0
- package/dist/esm/mediaQueries/moduleRegistry.d.ts.map +1 -0
- package/dist/esm/mediaQueries/moduleRegistry.js +1 -0
- package/dist/esm/mediaQueries/types.d.ts +17 -17
- package/dist/esm/mediaQueries/types.d.ts.map +1 -1
- package/package.json +15 -3
package/README.md
CHANGED
|
@@ -61,6 +61,34 @@ If you prefer, you can also import unit helpers from dedicated subpaths. For exa
|
|
|
61
61
|
|
|
62
62
|
---
|
|
63
63
|
|
|
64
|
+
## Media queries
|
|
65
|
+
|
|
66
|
+
```ts
|
|
67
|
+
import { m } from "css-calipers";
|
|
68
|
+
import { mediaQueryFactory } from "css-calipers/mediaQueries";
|
|
69
|
+
|
|
70
|
+
const media = mediaQueryFactory({
|
|
71
|
+
queries: {
|
|
72
|
+
mobile: { maxWidth: m(639) },
|
|
73
|
+
desktop: { minWidth: m(640) },
|
|
74
|
+
},
|
|
75
|
+
config: {
|
|
76
|
+
label: "layout",
|
|
77
|
+
},
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
const styles = {
|
|
81
|
+
...media({
|
|
82
|
+
mobile: { gridTemplateColumns: "1fr" },
|
|
83
|
+
desktop: { gridTemplateColumns: "repeat(4, 1fr)" },
|
|
84
|
+
}),
|
|
85
|
+
};
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
See README_MEDIAQUERIES.md for the full media queries guide.
|
|
89
|
+
|
|
90
|
+
---
|
|
91
|
+
|
|
64
92
|
## Features
|
|
65
93
|
|
|
66
94
|
- **Compile-time unit validation.** Prevents mixing incompatible units.
|
|
@@ -112,7 +140,7 @@ Itβs probably overkill if:
|
|
|
112
140
|
import { m, mPercent, mVw, mVh, assertCondition } from "css-calipers";
|
|
113
141
|
|
|
114
142
|
// Token-style measurements (px by default)
|
|
115
|
-
const spacing = m(8); // Defaults to px and is typed as a PxMeasurement
|
|
143
|
+
const spacing = m(8); // Defaults to px and is typed as a PxMeasurement
|
|
116
144
|
const cardPadding = spacing.multiply(2); // 16px
|
|
117
145
|
const gutter = spacing.multiply(1.5); // 12px
|
|
118
146
|
|
package/dist/cjs/index.js
CHANGED
|
@@ -28,3 +28,4 @@ __exportStar(require("./units/time"), exports);
|
|
|
28
28
|
__exportStar(require("./units/frequency"), exports);
|
|
29
29
|
__exportStar(require("./units/resolution"), exports);
|
|
30
30
|
__exportStar(require("./units/grid"), exports);
|
|
31
|
+
__exportStar(require("./libraryHelpers/vanilla-extract"), exports);
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.mediaQueryOutputVanillaExtract = void 0;
|
|
4
|
+
const mediaQueryOutputVanillaExtract = (media) => ({
|
|
5
|
+
'&': media,
|
|
6
|
+
});
|
|
7
|
+
exports.mediaQueryOutputVanillaExtract = mediaQueryOutputVanillaExtract;
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.mediaQueryFactory = void 0;
|
|
4
|
+
const helpers_1 = require("./helpers");
|
|
5
|
+
const mediaQueries_1 = require("./mediaQueries");
|
|
6
|
+
const modules_1 = require("./modules");
|
|
7
|
+
const ALL_MEDIA_QUERY_MODULES = [
|
|
8
|
+
'core',
|
|
9
|
+
'dimensions',
|
|
10
|
+
'resolution',
|
|
11
|
+
'interaction',
|
|
12
|
+
'preferences',
|
|
13
|
+
'display',
|
|
14
|
+
'environment',
|
|
15
|
+
'custom',
|
|
16
|
+
];
|
|
17
|
+
const MODULE_KEYS = {
|
|
18
|
+
core: ['type', 'minWidth', 'maxWidth'],
|
|
19
|
+
dimensions: [
|
|
20
|
+
'width',
|
|
21
|
+
'height',
|
|
22
|
+
'minHeight',
|
|
23
|
+
'maxHeight',
|
|
24
|
+
'aspectRatio',
|
|
25
|
+
'minAspectRatio',
|
|
26
|
+
'maxAspectRatio',
|
|
27
|
+
'orientation',
|
|
28
|
+
],
|
|
29
|
+
resolution: ['resolutionValue', 'minResolution', 'maxResolution'],
|
|
30
|
+
interaction: ['hover', 'anyHover', 'pointer', 'anyPointer', 'update'],
|
|
31
|
+
preferences: [
|
|
32
|
+
'colorScheme',
|
|
33
|
+
'reducedMotion',
|
|
34
|
+
'reducedData',
|
|
35
|
+
'contrast',
|
|
36
|
+
'forcedColors',
|
|
37
|
+
],
|
|
38
|
+
display: ['colorGamut', 'dynamicRange', 'invertedColors'],
|
|
39
|
+
environment: ['scripting', 'overflowBlock', 'overflowInline'],
|
|
40
|
+
custom: ['customFeatures'],
|
|
41
|
+
};
|
|
42
|
+
const MODULE_EMITTERS = {
|
|
43
|
+
core: mediaQueries_1.emitCoreFeatures,
|
|
44
|
+
dimensions: modules_1.emitDimensionsFeatures,
|
|
45
|
+
resolution: modules_1.emitResolutionFeatures,
|
|
46
|
+
interaction: modules_1.emitInteractionFeatures,
|
|
47
|
+
preferences: modules_1.emitPreferencesFeatures,
|
|
48
|
+
display: modules_1.emitDisplayFeatures,
|
|
49
|
+
environment: modules_1.emitEnvironmentFeatures,
|
|
50
|
+
custom: modules_1.emitCustomFeatures,
|
|
51
|
+
};
|
|
52
|
+
const ALL_MODULE_KEYS = MODULE_KEYS;
|
|
53
|
+
const KEY_TO_MODULE = Object.fromEntries(Object.keys(ALL_MODULE_KEYS).flatMap((moduleId) => ALL_MODULE_KEYS[moduleId].map((key) => [key, moduleId])));
|
|
54
|
+
const guardUnsupportedProps = (props, modules, config, label) => {
|
|
55
|
+
const allowed = new Set();
|
|
56
|
+
modules.forEach((moduleId) => {
|
|
57
|
+
ALL_MODULE_KEYS[moduleId].forEach((key) => {
|
|
58
|
+
allowed.add(key);
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
Object.keys(props).forEach((key) => {
|
|
62
|
+
var _a, _b;
|
|
63
|
+
if (props[key] === undefined)
|
|
64
|
+
return;
|
|
65
|
+
if (allowed.has(key))
|
|
66
|
+
return;
|
|
67
|
+
const mode = (_b = (_a = config.errorHandling) === null || _a === void 0 ? void 0 : _a.invalidValueMode) !== null && _b !== void 0 ? _b : 'throw';
|
|
68
|
+
const moduleHint = KEY_TO_MODULE[key];
|
|
69
|
+
const moduleSuffix = moduleHint
|
|
70
|
+
? ` Add "${moduleHint}" to modules.`
|
|
71
|
+
: '';
|
|
72
|
+
const message = `Media query factory "${label}" received unsupported feature "${key}".${moduleSuffix}`;
|
|
73
|
+
if (mode === 'log') {
|
|
74
|
+
console.warn(message);
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
if (mode === 'allow')
|
|
78
|
+
return;
|
|
79
|
+
throw new Error(message);
|
|
80
|
+
});
|
|
81
|
+
};
|
|
82
|
+
const normalizeCustomResult = (result) => {
|
|
83
|
+
if (result === undefined || result === null)
|
|
84
|
+
return { valid: true };
|
|
85
|
+
if (typeof result === 'boolean')
|
|
86
|
+
return { valid: result };
|
|
87
|
+
if (typeof result === 'string') {
|
|
88
|
+
return result ? { valid: false, message: result } : { valid: true };
|
|
89
|
+
}
|
|
90
|
+
return result;
|
|
91
|
+
};
|
|
92
|
+
const runCustomValidator = (props, config) => {
|
|
93
|
+
var _a, _b;
|
|
94
|
+
const custom = config.custom;
|
|
95
|
+
if (!(custom === null || custom === void 0 ? void 0 : custom.validator))
|
|
96
|
+
return;
|
|
97
|
+
const normalized = normalizeCustomResult(custom.validator(props));
|
|
98
|
+
if (normalized.valid)
|
|
99
|
+
return;
|
|
100
|
+
const mode = (_b = (_a = config.errorHandling) === null || _a === void 0 ? void 0 : _a.invalidValueMode) !== null && _b !== void 0 ? _b : 'throw';
|
|
101
|
+
const suffix = normalized.message ? `: ${normalized.message}` : '';
|
|
102
|
+
const message = `Media query factory "${config.label}" custom validator "${custom.key}" failed${suffix}`;
|
|
103
|
+
if (mode === 'log') {
|
|
104
|
+
console.warn(message);
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
if (mode === 'allow')
|
|
108
|
+
return;
|
|
109
|
+
throw new Error(message);
|
|
110
|
+
};
|
|
111
|
+
const runCustomLinter = (props, config) => {
|
|
112
|
+
var _a, _b;
|
|
113
|
+
const custom = config.custom;
|
|
114
|
+
if (!(custom === null || custom === void 0 ? void 0 : custom.linter))
|
|
115
|
+
return;
|
|
116
|
+
const normalized = normalizeCustomResult(custom.linter(props));
|
|
117
|
+
if (normalized.valid)
|
|
118
|
+
return;
|
|
119
|
+
const mode = (_b = (_a = config.errorHandling) === null || _a === void 0 ? void 0 : _a.lintingMode) !== null && _b !== void 0 ? _b : 'throw';
|
|
120
|
+
const suffix = normalized.message ? `: ${normalized.message}` : '';
|
|
121
|
+
const message = `Media query factory "${config.label}" custom linter "${custom.key}" flagged${suffix}`;
|
|
122
|
+
if (mode === 'log') {
|
|
123
|
+
console.warn(message);
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
if (mode === 'allow')
|
|
127
|
+
return;
|
|
128
|
+
throw new Error(message);
|
|
129
|
+
};
|
|
130
|
+
const mediaQueryFactory = (options) => {
|
|
131
|
+
var _a;
|
|
132
|
+
const modules = (_a = options.config.modules) !== null && _a !== void 0 ? _a : ALL_MEDIA_QUERY_MODULES;
|
|
133
|
+
const buildMediaQuery = (0, helpers_1.createMediaQueryBuilder)({
|
|
134
|
+
emitBase: (props, helpers) => {
|
|
135
|
+
guardUnsupportedProps(props, modules, options.config, options.config.label);
|
|
136
|
+
runCustomValidator(props, options.config);
|
|
137
|
+
runCustomLinter(props, options.config);
|
|
138
|
+
modules.forEach((moduleId) => {
|
|
139
|
+
MODULE_EMITTERS[moduleId](props, helpers);
|
|
140
|
+
});
|
|
141
|
+
},
|
|
142
|
+
resolveType: (props) => props.type,
|
|
143
|
+
config: options.config,
|
|
144
|
+
});
|
|
145
|
+
return (stylesByQuery) => {
|
|
146
|
+
const result = {};
|
|
147
|
+
Object.keys(stylesByQuery).forEach((key) => {
|
|
148
|
+
const styles = stylesByQuery[key];
|
|
149
|
+
const props = options.queries[key];
|
|
150
|
+
if (!styles || !props)
|
|
151
|
+
return;
|
|
152
|
+
result[buildMediaQuery(props)] = styles;
|
|
153
|
+
});
|
|
154
|
+
const mediaQuery = {
|
|
155
|
+
'@media': result,
|
|
156
|
+
};
|
|
157
|
+
return options.config.output
|
|
158
|
+
? options.config.output(mediaQuery)
|
|
159
|
+
: mediaQuery;
|
|
160
|
+
};
|
|
161
|
+
};
|
|
162
|
+
exports.mediaQueryFactory = mediaQueryFactory;
|
|
@@ -16,5 +16,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./types"), exports);
|
|
18
18
|
__exportStar(require("./helpers"), exports);
|
|
19
|
+
__exportStar(require("./factory"), exports);
|
|
19
20
|
__exportStar(require("./mediaQueries"), exports);
|
|
20
21
|
__exportStar(require("./modules"), exports);
|
|
22
|
+
__exportStar(require("./moduleRegistry"), exports);
|
|
@@ -5,7 +5,7 @@ const runMediaQueryLint = (config, helpers, check, message = 'Media query lint f
|
|
|
5
5
|
var _a, _b;
|
|
6
6
|
if (!check)
|
|
7
7
|
return true;
|
|
8
|
-
const mode = (_b = (_a = helpers.config.errorHandling) === null || _a === void 0 ? void 0 : _a.lintingMode) !== null && _b !== void 0 ? _b : '
|
|
8
|
+
const mode = (_b = (_a = helpers.config.errorHandling) === null || _a === void 0 ? void 0 : _a.lintingMode) !== null && _b !== void 0 ? _b : 'throw';
|
|
9
9
|
if (mode === 'allow')
|
|
10
10
|
return true;
|
|
11
11
|
if (mode === 'log') {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.makeMediaQueryStyle = exports.buildMediaQueryString = void 0;
|
|
3
|
+
exports.makeMediaQueryStyle = exports.buildMediaQueryString = exports.emitCoreFeatures = void 0;
|
|
4
4
|
const helpers_1 = require("./helpers");
|
|
5
5
|
const validation_1 = require("./validation");
|
|
6
6
|
const modules_1 = require("./modules");
|
|
@@ -19,8 +19,9 @@ const emitCoreFeatures = (props, helpers) => {
|
|
|
19
19
|
addFeature("max-width", props.maxWidth);
|
|
20
20
|
}
|
|
21
21
|
};
|
|
22
|
+
exports.emitCoreFeatures = emitCoreFeatures;
|
|
22
23
|
const emitBaseFeatures = (props, helpers) => {
|
|
23
|
-
emitCoreFeatures(props, helpers);
|
|
24
|
+
(0, exports.emitCoreFeatures)(props, helpers);
|
|
24
25
|
(0, modules_1.emitDimensionsFeatures)(props, helpers);
|
|
25
26
|
(0, modules_1.emitResolutionFeatures)(props, helpers);
|
|
26
27
|
(0, modules_1.emitInteractionFeatures)(props, helpers);
|
package/dist/esm/index.d.ts
CHANGED
package/dist/esm/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,QAAQ,CAAC;AAEvB,cAAc,iBAAiB,CAAC;AAChC,cAAc,kBAAkB,CAAC;AACjC,cAAc,uBAAuB,CAAC;AACtC,cAAc,kBAAkB,CAAC;AACjC,cAAc,wBAAwB,CAAC;AACvC,cAAc,wBAAwB,CAAC;AACvC,cAAc,0BAA0B,CAAC;AACzC,cAAc,mBAAmB,CAAC;AAClC,cAAc,eAAe,CAAC;AAC9B,cAAc,cAAc,CAAC;AAC7B,cAAc,mBAAmB,CAAC;AAClC,cAAc,oBAAoB,CAAC;AACnC,cAAc,cAAc,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,QAAQ,CAAC;AAEvB,cAAc,iBAAiB,CAAC;AAChC,cAAc,kBAAkB,CAAC;AACjC,cAAc,uBAAuB,CAAC;AACtC,cAAc,kBAAkB,CAAC;AACjC,cAAc,wBAAwB,CAAC;AACvC,cAAc,wBAAwB,CAAC;AACvC,cAAc,0BAA0B,CAAC;AACzC,cAAc,mBAAmB,CAAC;AAClC,cAAc,eAAe,CAAC;AAC9B,cAAc,cAAc,CAAC;AAC7B,cAAc,mBAAmB,CAAC;AAClC,cAAc,oBAAoB,CAAC;AACnC,cAAc,cAAc,CAAC;AAC7B,cAAc,kCAAkC,CAAC"}
|
package/dist/esm/index.js
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vanilla-extract.d.ts","sourceRoot":"","sources":["../../../src/libraryHelpers/vanilla-extract.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAE9D,eAAO,MAAM,8BAA8B,GACzC,OAAO,gBAAgB,KACtB,MAAM,CAAC,MAAM,EAAE,OAAO,CAEvB,CAAC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { ComplexStyleRule, StyleRule } from './types';
|
|
2
|
+
import type { MediaQueryBuilderConfig } from './helpers';
|
|
3
|
+
import type { IMediaQueryProps } from './mediaQueries';
|
|
4
|
+
import type { MediaQueryModulePropsMap, MediaQueryModulesList } from './moduleRegistry';
|
|
5
|
+
type UnionToIntersection<T> = (T extends unknown ? (value: T) => void : never) extends (value: infer R) => void ? R : never;
|
|
6
|
+
type ModulesToProps<TModules extends MediaQueryModulesList> = UnionToIntersection<MediaQueryModulePropsMap[TModules[number]]>;
|
|
7
|
+
type FactoryQueryProps<TModules extends MediaQueryModulesList | undefined> = TModules extends MediaQueryModulesList ? ModulesToProps<TModules> : IMediaQueryProps;
|
|
8
|
+
type MediaQueryStyleMap<TQueries> = Partial<Record<keyof TQueries, StyleRule>>;
|
|
9
|
+
type CustomHookResult = boolean | string | null | undefined | {
|
|
10
|
+
valid: boolean;
|
|
11
|
+
message?: string;
|
|
12
|
+
};
|
|
13
|
+
type MediaQueryFactoryCustomHooks = {
|
|
14
|
+
key: string;
|
|
15
|
+
validator?: (props: IMediaQueryProps) => CustomHookResult;
|
|
16
|
+
linter?: (props: IMediaQueryProps) => CustomHookResult;
|
|
17
|
+
};
|
|
18
|
+
export type MediaQueryFactoryConfig<TModules extends MediaQueryModulesList | undefined = undefined, TOutput = ComplexStyleRule> = MediaQueryBuilderConfig & {
|
|
19
|
+
label: string;
|
|
20
|
+
modules?: TModules;
|
|
21
|
+
output?: (media: ComplexStyleRule) => TOutput;
|
|
22
|
+
custom?: MediaQueryFactoryCustomHooks;
|
|
23
|
+
};
|
|
24
|
+
export declare const mediaQueryFactory: <TModules extends MediaQueryModulesList | undefined, TQueries extends Record<string, FactoryQueryProps<TModules>>, TOutput = ComplexStyleRule>(options: {
|
|
25
|
+
queries: TQueries;
|
|
26
|
+
config: MediaQueryFactoryConfig<TModules, TOutput>;
|
|
27
|
+
}) => (stylesByQuery: MediaQueryStyleMap<TQueries>) => TOutput;
|
|
28
|
+
export {};
|
|
29
|
+
//# sourceMappingURL=factory.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"factory.d.ts","sourceRoot":"","sources":["../../../src/mediaQueries/factory.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAC3D,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,WAAW,CAAC;AAEzD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAWvD,OAAO,KAAK,EAEV,wBAAwB,EACxB,qBAAqB,EACtB,MAAM,kBAAkB,CAAC;AAE1B,KAAK,mBAAmB,CAAC,CAAC,IAAI,CAC5B,CAAC,SAAS,OAAO,GAAG,CAAC,KAAK,EAAE,CAAC,KAAK,IAAI,GAAG,KAAK,CAC/C,SAAS,CAAC,KAAK,EAAE,MAAM,CAAC,KAAK,IAAI,GAC9B,CAAC,GACD,KAAK,CAAC;AAEV,KAAK,cAAc,CAAC,QAAQ,SAAS,qBAAqB,IACxD,mBAAmB,CAAC,wBAAwB,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;AAElE,KAAK,iBAAiB,CAAC,QAAQ,SAAS,qBAAqB,GAAG,SAAS,IACvE,QAAQ,SAAS,qBAAqB,GAClC,cAAc,CAAC,QAAQ,CAAC,GACxB,gBAAgB,CAAC;AAEvB,KAAK,kBAAkB,CAAC,QAAQ,IAAI,OAAO,CACzC,MAAM,CAAC,MAAM,QAAQ,EAAE,SAAS,CAAC,CAClC,CAAC;AAEF,KAAK,gBAAgB,GACjB,OAAO,GACP,MAAM,GACN,IAAI,GACJ,SAAS,GACT;IACE,KAAK,EAAE,OAAO,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB,CAAC;AAEN,KAAK,4BAA4B,GAAG;IAClC,GAAG,EAAE,MAAM,CAAC;IACZ,SAAS,CAAC,EAAE,CAAC,KAAK,EAAE,gBAAgB,KAAK,gBAAgB,CAAC;IAC1D,MAAM,CAAC,EAAE,CAAC,KAAK,EAAE,gBAAgB,KAAK,gBAAgB,CAAC;CACxD,CAAC;AA+FF,MAAM,MAAM,uBAAuB,CACjC,QAAQ,SAAS,qBAAqB,GAAG,SAAS,GAAG,SAAS,EAC9D,OAAO,GAAG,gBAAgB,IACxB,uBAAuB,GAAG;IAC5B,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,QAAQ,CAAC;IACnB,MAAM,CAAC,EAAE,CAAC,KAAK,EAAE,gBAAgB,KAAK,OAAO,CAAC;IAC9C,MAAM,CAAC,EAAE,4BAA4B,CAAC;CACvC,CAAC;AA2DF,eAAO,MAAM,iBAAiB,GAC5B,QAAQ,SAAS,qBAAqB,GAAG,SAAS,EAClD,QAAQ,SAAS,MAAM,CAAC,MAAM,EAAE,iBAAiB,CAAC,QAAQ,CAAC,CAAC,EAC5D,OAAO,GAAG,gBAAgB,EAC1B,SAAS;IACT,OAAO,EAAE,QAAQ,CAAC;IAClB,MAAM,EAAE,uBAAuB,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;CACpD,MAuBS,eAAe,kBAAkB,CAAC,QAAQ,CAAC,KAAG,OAkBvD,CAAC"}
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
import { createMediaQueryBuilder } from './helpers';
|
|
2
|
+
import { emitCoreFeatures } from './mediaQueries';
|
|
3
|
+
import { emitCustomFeatures, emitDimensionsFeatures, emitDisplayFeatures, emitEnvironmentFeatures, emitInteractionFeatures, emitPreferencesFeatures, emitResolutionFeatures, } from './modules';
|
|
4
|
+
const ALL_MEDIA_QUERY_MODULES = [
|
|
5
|
+
'core',
|
|
6
|
+
'dimensions',
|
|
7
|
+
'resolution',
|
|
8
|
+
'interaction',
|
|
9
|
+
'preferences',
|
|
10
|
+
'display',
|
|
11
|
+
'environment',
|
|
12
|
+
'custom',
|
|
13
|
+
];
|
|
14
|
+
const MODULE_KEYS = {
|
|
15
|
+
core: ['type', 'minWidth', 'maxWidth'],
|
|
16
|
+
dimensions: [
|
|
17
|
+
'width',
|
|
18
|
+
'height',
|
|
19
|
+
'minHeight',
|
|
20
|
+
'maxHeight',
|
|
21
|
+
'aspectRatio',
|
|
22
|
+
'minAspectRatio',
|
|
23
|
+
'maxAspectRatio',
|
|
24
|
+
'orientation',
|
|
25
|
+
],
|
|
26
|
+
resolution: ['resolutionValue', 'minResolution', 'maxResolution'],
|
|
27
|
+
interaction: ['hover', 'anyHover', 'pointer', 'anyPointer', 'update'],
|
|
28
|
+
preferences: [
|
|
29
|
+
'colorScheme',
|
|
30
|
+
'reducedMotion',
|
|
31
|
+
'reducedData',
|
|
32
|
+
'contrast',
|
|
33
|
+
'forcedColors',
|
|
34
|
+
],
|
|
35
|
+
display: ['colorGamut', 'dynamicRange', 'invertedColors'],
|
|
36
|
+
environment: ['scripting', 'overflowBlock', 'overflowInline'],
|
|
37
|
+
custom: ['customFeatures'],
|
|
38
|
+
};
|
|
39
|
+
const MODULE_EMITTERS = {
|
|
40
|
+
core: emitCoreFeatures,
|
|
41
|
+
dimensions: emitDimensionsFeatures,
|
|
42
|
+
resolution: emitResolutionFeatures,
|
|
43
|
+
interaction: emitInteractionFeatures,
|
|
44
|
+
preferences: emitPreferencesFeatures,
|
|
45
|
+
display: emitDisplayFeatures,
|
|
46
|
+
environment: emitEnvironmentFeatures,
|
|
47
|
+
custom: emitCustomFeatures,
|
|
48
|
+
};
|
|
49
|
+
const ALL_MODULE_KEYS = MODULE_KEYS;
|
|
50
|
+
const KEY_TO_MODULE = Object.fromEntries(Object.keys(ALL_MODULE_KEYS).flatMap((moduleId) => ALL_MODULE_KEYS[moduleId].map((key) => [key, moduleId])));
|
|
51
|
+
const guardUnsupportedProps = (props, modules, config, label) => {
|
|
52
|
+
const allowed = new Set();
|
|
53
|
+
modules.forEach((moduleId) => {
|
|
54
|
+
ALL_MODULE_KEYS[moduleId].forEach((key) => {
|
|
55
|
+
allowed.add(key);
|
|
56
|
+
});
|
|
57
|
+
});
|
|
58
|
+
Object.keys(props).forEach((key) => {
|
|
59
|
+
var _a, _b;
|
|
60
|
+
if (props[key] === undefined)
|
|
61
|
+
return;
|
|
62
|
+
if (allowed.has(key))
|
|
63
|
+
return;
|
|
64
|
+
const mode = (_b = (_a = config.errorHandling) === null || _a === void 0 ? void 0 : _a.invalidValueMode) !== null && _b !== void 0 ? _b : 'throw';
|
|
65
|
+
const moduleHint = KEY_TO_MODULE[key];
|
|
66
|
+
const moduleSuffix = moduleHint
|
|
67
|
+
? ` Add "${moduleHint}" to modules.`
|
|
68
|
+
: '';
|
|
69
|
+
const message = `Media query factory "${label}" received unsupported feature "${key}".${moduleSuffix}`;
|
|
70
|
+
if (mode === 'log') {
|
|
71
|
+
console.warn(message);
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
if (mode === 'allow')
|
|
75
|
+
return;
|
|
76
|
+
throw new Error(message);
|
|
77
|
+
});
|
|
78
|
+
};
|
|
79
|
+
const normalizeCustomResult = (result) => {
|
|
80
|
+
if (result === undefined || result === null)
|
|
81
|
+
return { valid: true };
|
|
82
|
+
if (typeof result === 'boolean')
|
|
83
|
+
return { valid: result };
|
|
84
|
+
if (typeof result === 'string') {
|
|
85
|
+
return result ? { valid: false, message: result } : { valid: true };
|
|
86
|
+
}
|
|
87
|
+
return result;
|
|
88
|
+
};
|
|
89
|
+
const runCustomValidator = (props, config) => {
|
|
90
|
+
var _a, _b;
|
|
91
|
+
const custom = config.custom;
|
|
92
|
+
if (!(custom === null || custom === void 0 ? void 0 : custom.validator))
|
|
93
|
+
return;
|
|
94
|
+
const normalized = normalizeCustomResult(custom.validator(props));
|
|
95
|
+
if (normalized.valid)
|
|
96
|
+
return;
|
|
97
|
+
const mode = (_b = (_a = config.errorHandling) === null || _a === void 0 ? void 0 : _a.invalidValueMode) !== null && _b !== void 0 ? _b : 'throw';
|
|
98
|
+
const suffix = normalized.message ? `: ${normalized.message}` : '';
|
|
99
|
+
const message = `Media query factory "${config.label}" custom validator "${custom.key}" failed${suffix}`;
|
|
100
|
+
if (mode === 'log') {
|
|
101
|
+
console.warn(message);
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
if (mode === 'allow')
|
|
105
|
+
return;
|
|
106
|
+
throw new Error(message);
|
|
107
|
+
};
|
|
108
|
+
const runCustomLinter = (props, config) => {
|
|
109
|
+
var _a, _b;
|
|
110
|
+
const custom = config.custom;
|
|
111
|
+
if (!(custom === null || custom === void 0 ? void 0 : custom.linter))
|
|
112
|
+
return;
|
|
113
|
+
const normalized = normalizeCustomResult(custom.linter(props));
|
|
114
|
+
if (normalized.valid)
|
|
115
|
+
return;
|
|
116
|
+
const mode = (_b = (_a = config.errorHandling) === null || _a === void 0 ? void 0 : _a.lintingMode) !== null && _b !== void 0 ? _b : 'throw';
|
|
117
|
+
const suffix = normalized.message ? `: ${normalized.message}` : '';
|
|
118
|
+
const message = `Media query factory "${config.label}" custom linter "${custom.key}" flagged${suffix}`;
|
|
119
|
+
if (mode === 'log') {
|
|
120
|
+
console.warn(message);
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
if (mode === 'allow')
|
|
124
|
+
return;
|
|
125
|
+
throw new Error(message);
|
|
126
|
+
};
|
|
127
|
+
export const mediaQueryFactory = (options) => {
|
|
128
|
+
var _a;
|
|
129
|
+
const modules = (_a = options.config.modules) !== null && _a !== void 0 ? _a : ALL_MEDIA_QUERY_MODULES;
|
|
130
|
+
const buildMediaQuery = createMediaQueryBuilder({
|
|
131
|
+
emitBase: (props, helpers) => {
|
|
132
|
+
guardUnsupportedProps(props, modules, options.config, options.config.label);
|
|
133
|
+
runCustomValidator(props, options.config);
|
|
134
|
+
runCustomLinter(props, options.config);
|
|
135
|
+
modules.forEach((moduleId) => {
|
|
136
|
+
MODULE_EMITTERS[moduleId](props, helpers);
|
|
137
|
+
});
|
|
138
|
+
},
|
|
139
|
+
resolveType: (props) => props.type,
|
|
140
|
+
config: options.config,
|
|
141
|
+
});
|
|
142
|
+
return (stylesByQuery) => {
|
|
143
|
+
const result = {};
|
|
144
|
+
Object.keys(stylesByQuery).forEach((key) => {
|
|
145
|
+
const styles = stylesByQuery[key];
|
|
146
|
+
const props = options.queries[key];
|
|
147
|
+
if (!styles || !props)
|
|
148
|
+
return;
|
|
149
|
+
result[buildMediaQuery(props)] = styles;
|
|
150
|
+
});
|
|
151
|
+
const mediaQuery = {
|
|
152
|
+
'@media': result,
|
|
153
|
+
};
|
|
154
|
+
return options.config.output
|
|
155
|
+
? options.config.output(mediaQuery)
|
|
156
|
+
: mediaQuery;
|
|
157
|
+
};
|
|
158
|
+
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/mediaQueries/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC;AACxB,cAAc,WAAW,CAAC;AAC1B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,WAAW,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/mediaQueries/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC;AACxB,cAAc,WAAW,CAAC;AAC1B,cAAc,WAAW,CAAC;AAC1B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,WAAW,CAAC;AAC1B,cAAc,kBAAkB,CAAC"}
|
|
@@ -2,7 +2,7 @@ export const runMediaQueryLint = (config, helpers, check, message = 'Media query
|
|
|
2
2
|
var _a, _b;
|
|
3
3
|
if (!check)
|
|
4
4
|
return true;
|
|
5
|
-
const mode = (_b = (_a = helpers.config.errorHandling) === null || _a === void 0 ? void 0 : _a.lintingMode) !== null && _b !== void 0 ? _b : '
|
|
5
|
+
const mode = (_b = (_a = helpers.config.errorHandling) === null || _a === void 0 ? void 0 : _a.lintingMode) !== null && _b !== void 0 ? _b : 'throw';
|
|
6
6
|
if (mode === 'allow')
|
|
7
7
|
return true;
|
|
8
8
|
if (mode === 'log') {
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { IMeasurement } from "../core";
|
|
2
2
|
import type { ComplexStyleRule, StyleRule } from "./types";
|
|
3
|
+
import type { MediaQueryBuilderHelpers } from "./helpers";
|
|
3
4
|
import { IMediaQueryCustomFeatures, IMediaQueryDimensions, IMediaQueryDisplay, IMediaQueryEnvironment, IMediaQueryInteraction, IMediaQueryPreferences, IMediaQueryResolutionRange } from "./modules";
|
|
4
5
|
export interface IMediaQueryProps extends IMediaQueryCore, IMediaQueryDimensions, IMediaQueryResolutionRange, IMediaQueryInteraction, IMediaQueryPreferences, IMediaQueryDisplay, IMediaQueryEnvironment, IMediaQueryCustomFeatures {
|
|
5
6
|
}
|
|
@@ -14,6 +15,7 @@ export interface IMediaQuery {
|
|
|
14
15
|
}
|
|
15
16
|
export type IMediaQueries = Record<string, IMediaQueryProps>;
|
|
16
17
|
export type IMediaQueryStyles<T extends IMediaQueries> = Partial<Record<keyof T, StyleRule>>;
|
|
18
|
+
export declare const emitCoreFeatures: (props: IMediaQueryCore, helpers: MediaQueryBuilderHelpers) => void;
|
|
17
19
|
export declare const buildMediaQueryString: (config: IMediaQueryProps) => string;
|
|
18
20
|
export declare const makeMediaQueryStyle: <T extends IMediaQueries>(queries: T) => (stylesByQuery: IMediaQueryStyles<T>) => ComplexStyleRule;
|
|
19
21
|
//# sourceMappingURL=mediaQueries.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mediaQueries.d.ts","sourceRoot":"","sources":["../../../src/mediaQueries/mediaQueries.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM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AC;AAEH,eAAO,MAAM,mBAAmB,GAC7B,CAAC,SAAS,aAAa,EAAE,SAAS,CAAC,MACnC,eAAe,iBAAiB,CAAC,CAAC,CAAC,KAAG,gBActC,CAAC"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { createMediaQueryBuilder } from "./helpers";
|
|
2
2
|
import { runMediaQueryValidation, validateMinMaxWidth, validateWidthValuesPositive, } from "./validation";
|
|
3
3
|
import { emitCustomFeatures, emitDimensionsFeatures, emitDisplayFeatures, emitEnvironmentFeatures, emitInteractionFeatures, emitPreferencesFeatures, emitResolutionFeatures, } from "./modules";
|
|
4
|
-
const emitCoreFeatures = (props, helpers) => {
|
|
4
|
+
export const emitCoreFeatures = (props, helpers) => {
|
|
5
5
|
if (!runMediaQueryValidation(props, helpers, validateMinMaxWidth, "core", "minWidth must be less than or equal to maxWidth")) {
|
|
6
6
|
return;
|
|
7
7
|
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { IMediaQueryCore } from './mediaQueries';
|
|
2
|
+
import type { IMediaQueryCustomFeatures, IMediaQueryDimensions, IMediaQueryDisplay, IMediaQueryEnvironment, IMediaQueryInteraction, IMediaQueryPreferences, IMediaQueryResolutionRange } from './modules';
|
|
3
|
+
export type MediaQueryModuleId = 'core' | 'dimensions' | 'resolution' | 'interaction' | 'preferences' | 'display' | 'environment' | 'custom';
|
|
4
|
+
export type MediaQueryModulePropsMap = {
|
|
5
|
+
core: IMediaQueryCore;
|
|
6
|
+
dimensions: IMediaQueryDimensions;
|
|
7
|
+
resolution: IMediaQueryResolutionRange;
|
|
8
|
+
interaction: IMediaQueryInteraction;
|
|
9
|
+
preferences: IMediaQueryPreferences;
|
|
10
|
+
display: IMediaQueryDisplay;
|
|
11
|
+
environment: IMediaQueryEnvironment;
|
|
12
|
+
custom: IMediaQueryCustomFeatures;
|
|
13
|
+
};
|
|
14
|
+
export type MediaQueryModuleKeysMap = {
|
|
15
|
+
core: 'type' | 'minWidth' | 'maxWidth';
|
|
16
|
+
dimensions: 'width' | 'height' | 'minHeight' | 'maxHeight' | 'aspectRatio' | 'minAspectRatio' | 'maxAspectRatio' | 'orientation';
|
|
17
|
+
resolution: 'resolutionValue' | 'minResolution' | 'maxResolution';
|
|
18
|
+
interaction: 'hover' | 'anyHover' | 'pointer' | 'anyPointer' | 'update';
|
|
19
|
+
preferences: 'colorScheme' | 'reducedMotion' | 'reducedData' | 'contrast' | 'forcedColors';
|
|
20
|
+
display: 'colorGamut' | 'dynamicRange' | 'invertedColors';
|
|
21
|
+
environment: 'scripting' | 'overflowBlock' | 'overflowInline';
|
|
22
|
+
custom: 'customFeatures';
|
|
23
|
+
};
|
|
24
|
+
export type MediaQueryModuleKeys<M extends MediaQueryModuleId> = MediaQueryModuleKeysMap[M];
|
|
25
|
+
export type MediaQueryModulesList = readonly MediaQueryModuleId[];
|
|
26
|
+
export declare const defineMediaQueryModules: <T extends MediaQueryModulesList>(...modules: T) => T;
|
|
27
|
+
//# sourceMappingURL=moduleRegistry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"moduleRegistry.d.ts","sourceRoot":"","sources":["../../../src/mediaQueries/moduleRegistry.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AACtD,OAAO,KAAK,EACV,yBAAyB,EACzB,qBAAqB,EACrB,kBAAkB,EAClB,sBAAsB,EACtB,sBAAsB,EACtB,sBAAsB,EACtB,0BAA0B,EAC3B,MAAM,WAAW,CAAC;AAEnB,MAAM,MAAM,kBAAkB,GAC1B,MAAM,GACN,YAAY,GACZ,YAAY,GACZ,aAAa,GACb,aAAa,GACb,SAAS,GACT,aAAa,GACb,QAAQ,CAAC;AAEb,MAAM,MAAM,wBAAwB,GAAG;IACrC,IAAI,EAAE,eAAe,CAAC;IACtB,UAAU,EAAE,qBAAqB,CAAC;IAClC,UAAU,EAAE,0BAA0B,CAAC;IACvC,WAAW,EAAE,sBAAsB,CAAC;IACpC,WAAW,EAAE,sBAAsB,CAAC;IACpC,OAAO,EAAE,kBAAkB,CAAC;IAC5B,WAAW,EAAE,sBAAsB,CAAC;IACpC,MAAM,EAAE,yBAAyB,CAAC;CACnC,CAAC;AAEF,MAAM,MAAM,uBAAuB,GAAG;IACpC,IAAI,EAAE,MAAM,GAAG,UAAU,GAAG,UAAU,CAAC;IACvC,UAAU,EACN,OAAO,GACP,QAAQ,GACR,WAAW,GACX,WAAW,GACX,aAAa,GACb,gBAAgB,GAChB,gBAAgB,GAChB,aAAa,CAAC;IAClB,UAAU,EAAE,iBAAiB,GAAG,eAAe,GAAG,eAAe,CAAC;IAClE,WAAW,EAAE,OAAO,GAAG,UAAU,GAAG,SAAS,GAAG,YAAY,GAAG,QAAQ,CAAC;IACxE,WAAW,EACP,aAAa,GACb,eAAe,GACf,aAAa,GACb,UAAU,GACV,cAAc,CAAC;IACnB,OAAO,EAAE,YAAY,GAAG,cAAc,GAAG,gBAAgB,CAAC;IAC1D,WAAW,EAAE,WAAW,GAAG,eAAe,GAAG,gBAAgB,CAAC;IAC9D,MAAM,EAAE,gBAAgB,CAAC;CAC1B,CAAC;AAEF,MAAM,MAAM,oBAAoB,CAAC,CAAC,SAAS,kBAAkB,IAC3D,uBAAuB,CAAC,CAAC,CAAC,CAAC;AAE7B,MAAM,MAAM,qBAAqB,GAAG,SAAS,kBAAkB,EAAE,CAAC;AAElE,eAAO,MAAM,uBAAuB,GAAI,CAAC,SAAS,qBAAqB,EACrE,GAAG,SAAS,CAAC,KACZ,CAAY,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const defineMediaQueryModules = (...modules) => modules;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { AtRule, Properties } from
|
|
1
|
+
import type { AtRule, Properties } from "csstype";
|
|
2
2
|
export type Resolve<T> = {
|
|
3
3
|
[Key in keyof T]: T[Key];
|
|
4
4
|
} & {};
|
|
@@ -28,17 +28,17 @@ type Query<Key extends string, StyleType> = {
|
|
|
28
28
|
[query: string]: Omit<StyleType, Key>;
|
|
29
29
|
};
|
|
30
30
|
};
|
|
31
|
-
export type MediaQueries<StyleType> = Query<
|
|
32
|
-
export type FeatureQueries<StyleType> = Query<
|
|
33
|
-
export type ContainerQueries<StyleType> = Query<
|
|
34
|
-
export type Layers<StyleType> = Query<
|
|
31
|
+
export type MediaQueries<StyleType> = Query<"@media", StyleType>;
|
|
32
|
+
export type FeatureQueries<StyleType> = Query<"@supports", StyleType>;
|
|
33
|
+
export type ContainerQueries<StyleType> = Query<"@container", StyleType>;
|
|
34
|
+
export type Layers<StyleType> = Query<"@layer", StyleType>;
|
|
35
35
|
export type StartingStyle<StyleType> = {
|
|
36
|
-
|
|
36
|
+
"@starting-style"?: Omit<StyleType, "@starting-style">;
|
|
37
37
|
};
|
|
38
38
|
interface AllQueries<StyleType> extends MediaQueries<StyleType & AllQueries<StyleType>>, FeatureQueries<StyleType & AllQueries<StyleType>>, ContainerQueries<StyleType & AllQueries<StyleType>>, Layers<StyleType & AllQueries<StyleType>>, StartingStyle<StyleType> {
|
|
39
39
|
}
|
|
40
40
|
export type WithQueries<StyleType> = StyleType & AllQueries<StyleType>;
|
|
41
|
-
interface SelectorMap {
|
|
41
|
+
export interface SelectorMap {
|
|
42
42
|
[selector: string]: WithQueries<CSSPropertiesWithVars>;
|
|
43
43
|
}
|
|
44
44
|
export interface StyleWithSelectors extends CSSPropertiesAndPseudos {
|
|
@@ -46,33 +46,33 @@ export interface StyleWithSelectors extends CSSPropertiesAndPseudos {
|
|
|
46
46
|
}
|
|
47
47
|
export type StyleRule = WithQueries<StyleWithSelectors>;
|
|
48
48
|
export type GlobalStyleRule = WithQueries<CSSPropertiesWithVars>;
|
|
49
|
-
export type GlobalFontFaceRule = Omit<AtRule.FontFaceFallback,
|
|
50
|
-
export type FontFaceRule = Omit<GlobalFontFaceRule,
|
|
49
|
+
export type GlobalFontFaceRule = Omit<AtRule.FontFaceFallback, "src"> & Required<Pick<AtRule.FontFaceFallback, "src">>;
|
|
50
|
+
export type FontFaceRule = Omit<GlobalFontFaceRule, "fontFamily">;
|
|
51
51
|
export type CSSStyleBlock = {
|
|
52
|
-
type:
|
|
52
|
+
type: "local";
|
|
53
53
|
selector: string;
|
|
54
54
|
rule: StyleRule;
|
|
55
55
|
};
|
|
56
56
|
export type CSSFontFaceBlock = {
|
|
57
|
-
type:
|
|
57
|
+
type: "fontFace";
|
|
58
58
|
rule: GlobalFontFaceRule;
|
|
59
59
|
};
|
|
60
60
|
export type CSSKeyframesBlock = {
|
|
61
|
-
type:
|
|
61
|
+
type: "keyframes";
|
|
62
62
|
name: string;
|
|
63
63
|
rule: CSSKeyframes;
|
|
64
64
|
};
|
|
65
65
|
export type CSSSelectorBlock = {
|
|
66
|
-
type:
|
|
66
|
+
type: "selector" | "global";
|
|
67
67
|
selector: string;
|
|
68
68
|
rule: GlobalStyleRule;
|
|
69
69
|
};
|
|
70
70
|
export type CSSLayerDeclaration = {
|
|
71
|
-
type:
|
|
71
|
+
type: "layer";
|
|
72
72
|
name: string;
|
|
73
73
|
};
|
|
74
74
|
export type CSSPropertyBlock = {
|
|
75
|
-
type:
|
|
75
|
+
type: "property";
|
|
76
76
|
name: string;
|
|
77
77
|
rule: AtRule.Property;
|
|
78
78
|
};
|
|
@@ -91,7 +91,7 @@ type CustomIdentFunction = (params: {
|
|
|
91
91
|
debugId?: string;
|
|
92
92
|
packageName?: string;
|
|
93
93
|
}) => string;
|
|
94
|
-
type IdentOption =
|
|
94
|
+
type IdentOption = "short" | "debug" | CustomIdentFunction;
|
|
95
95
|
export interface Adapter {
|
|
96
96
|
appendCss: (css: CSS, fileScope: FileScope) => void;
|
|
97
97
|
registerClassName: (className: string, fileScope: FileScope) => void;
|
|
@@ -110,7 +110,7 @@ export type Tokens = {
|
|
|
110
110
|
export type ThemeVars<ThemeContract extends NullableTokens> = MapLeafNodes<ThemeContract, CSSVarFunction>;
|
|
111
111
|
export type ClassNames = string | Array<ClassNames>;
|
|
112
112
|
export type ComplexStyleRule = StyleRule | Array<StyleRule | ClassNames>;
|
|
113
|
-
type _PropertySyntax =
|
|
113
|
+
type _PropertySyntax = "<angle>" | "<color>" | "<custom-ident>" | "<image>" | "<integer>" | "<length-percentage>" | "<length>" | "<number>" | "<percentage>" | "<resolution>" | "<string>" | "<time>" | "<transform-function>" | "<transform-list>" | "<url>" | "*";
|
|
114
114
|
type LooseAutocomplete<Suggestions extends string> = Suggestions | Omit<string, Suggestions>;
|
|
115
115
|
export type PropertySyntax = LooseAutocomplete<_PropertySyntax>;
|
|
116
116
|
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/mediaQueries/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAElD,MAAM,MAAM,OAAO,CAAC,CAAC,IAAI;KACtB,GAAG,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC;CACzB,GAAG,EAAE,CAAC;AAEP,MAAM,MAAM,cAAc,GAAG,MAAM,CAAC;AAEpC,MAAM,MAAM,YAAY,CAAC,CAAC,EAAE,IAAI,IAAI,CAAC,SAAS,IAAI,GAC9C,IAAI,GACJ,CAAC,SAAS,MAAM,
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/mediaQueries/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAElD,MAAM,MAAM,OAAO,CAAC,CAAC,IAAI;KACtB,GAAG,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC;CACzB,GAAG,EAAE,CAAC;AAEP,MAAM,MAAM,cAAc,GAAG,MAAM,CAAC;AAEpC,MAAM,MAAM,YAAY,CAAC,CAAC,EAAE,IAAI,IAAI,CAAC,SAAS,IAAI,GAC9C,IAAI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AS,GACT,WAAW,GACX,qBAAqB,GACrB,UAAU,GACV,UAAU,GACV,cAAc,GACd,cAAc,GACd,UAAU,GACV,QAAQ,GACR,sBAAsB,GACtB,kBAAkB,GAClB,OAAO,GACP,GAAG,CAAC;AAER,KAAK,iBAAiB,CAAC,WAAW,SAAS,MAAM,IAC7C,WAAW,GACX,IAAI,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC;AAE9B,MAAM,MAAM,cAAc,GAAG,iBAAiB,CAAC,eAAe,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "css-calipers",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.1",
|
|
4
4
|
"description": "Compile-time unit safety for numeric, unit-bearing CSS values via typed measurements.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -57,14 +57,23 @@
|
|
|
57
57
|
"import": "./dist/esm/units/*.js",
|
|
58
58
|
"require": "./dist/cjs/units/*.js"
|
|
59
59
|
},
|
|
60
|
+
"./libraryHelpers/vanilla-extract": {
|
|
61
|
+
"types": "./dist/esm/libraryHelpers/vanilla-extract.d.ts",
|
|
62
|
+
"import": "./dist/esm/libraryHelpers/vanilla-extract.js",
|
|
63
|
+
"require": "./dist/cjs/libraryHelpers/vanilla-extract.js"
|
|
64
|
+
},
|
|
60
65
|
"./package.json": "./package.json"
|
|
61
66
|
},
|
|
62
67
|
"dependencies": {
|
|
63
68
|
"csstype": "^3.1.3"
|
|
64
69
|
},
|
|
65
70
|
"devDependencies": {
|
|
71
|
+
"@eslint/js": "^9.39.2",
|
|
66
72
|
"@types/node": "^24.10.1",
|
|
73
|
+
"@typescript-eslint/eslint-plugin": "^8.50.1",
|
|
74
|
+
"@typescript-eslint/parser": "^8.50.1",
|
|
67
75
|
"@vitest/coverage-v8": "^4.0.14",
|
|
76
|
+
"eslint": "^9.39.2",
|
|
68
77
|
"tsd": "^0.31.0",
|
|
69
78
|
"typescript": "^5.6.3",
|
|
70
79
|
"vitest": "^4.0.14"
|
|
@@ -78,7 +87,7 @@
|
|
|
78
87
|
"prepublishOnly": "node -e \"if (!process.env.CSS_CALIPERS_RELEASE) { console.error('Direct npm publish is disabled; use \\\"npm run release\\\" instead.'); process.exit(1); }\"",
|
|
79
88
|
"release": "node scripts/release.mjs",
|
|
80
89
|
"release:dry": "node scripts/release.mjs --dry-run",
|
|
81
|
-
"test": "npm run test:core && npm run test:mediaQueries && npm run test:dist && npm run test:types",
|
|
90
|
+
"test": "npm run test:core && npm run test:mediaQueries && npm run test:dist && npm run test:types && npm run test:tsc && npm run lint",
|
|
82
91
|
"test:mediaQueries": "vitest run tests/runtime/mediaQueries/mediaQueries.src.test.ts",
|
|
83
92
|
"test:mediaQueries:cjs": "vitest run tests/runtime/mediaQueries/mediaQueries.cjs.test.ts tests/runtime/api-surface/mediaQueries.api-surface.cjs.test.ts",
|
|
84
93
|
"test:mediaQueries:esm": "vitest run tests/runtime/mediaQueries/mediaQueries.esm.test.ts tests/runtime/api-surface/mediaQueries.api-surface.esm.test.ts",
|
|
@@ -87,7 +96,10 @@
|
|
|
87
96
|
"test:core:cjs": "vitest run tests/runtime/core/core.cjs.test.ts tests/runtime/api-surface/api-surface.cjs.test.ts",
|
|
88
97
|
"test:core:esm": "vitest run tests/runtime/core/core.esm.test.ts tests/runtime/api-surface/api-surface.esm.test.ts",
|
|
89
98
|
"test:core:dist": "npm run test:core:cjs && npm run test:core:esm",
|
|
99
|
+
"lint": "eslint . --max-warnings=0",
|
|
100
|
+
"test:lint": "npm run lint",
|
|
90
101
|
"test:types": "echo \"\n π§ͺ Starting tsd type checks...\n\" && tsd --files tests/types/**/*.test-d.ts && echo \"β
tsd type checks passed!\n\"",
|
|
91
|
-
"test:
|
|
102
|
+
"test:tsc": "tsc -p tsconfig.json --noEmit",
|
|
103
|
+
"test:dist": "npm run build && npm run test:core:dist && npm run test:mediaQueries:dist"
|
|
92
104
|
}
|
|
93
105
|
}
|