css-calipers 0.7.0 → 0.8.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 +7 -0
- package/dist/cjs/mediaQueries/helpers.js +97 -0
- package/dist/cjs/mediaQueries/index.js +20 -0
- package/dist/cjs/mediaQueries/linting/core.js +19 -0
- package/dist/cjs/mediaQueries/linting/resolution.js +11 -0
- package/dist/cjs/mediaQueries/linting.js +24 -0
- package/dist/cjs/mediaQueries/mediaQueries.js +50 -0
- package/dist/cjs/mediaQueries/mediaQueryFactory.js +120 -0
- package/dist/cjs/mediaQueries/modules/custom.js +26 -0
- package/dist/cjs/mediaQueries/modules/dimensions.js +59 -0
- package/dist/cjs/mediaQueries/modules/display.js +20 -0
- package/dist/cjs/mediaQueries/modules/environment.js +20 -0
- package/dist/cjs/mediaQueries/modules/index.js +23 -0
- package/dist/cjs/mediaQueries/modules/interaction.js +26 -0
- package/dist/cjs/mediaQueries/modules/preferences.js +26 -0
- package/dist/cjs/mediaQueries/modules/resolution.js +29 -0
- package/dist/cjs/mediaQueries/types.js +2 -0
- package/dist/cjs/mediaQueries/validation.js +133 -0
- package/dist/esm/mediaQueries/helpers.d.ts +40 -0
- package/dist/esm/mediaQueries/helpers.d.ts.map +1 -0
- package/dist/esm/mediaQueries/helpers.js +87 -0
- package/dist/esm/mediaQueries/index.d.ts +5 -0
- package/dist/esm/mediaQueries/index.d.ts.map +1 -0
- package/dist/esm/mediaQueries/index.js +4 -0
- package/dist/esm/mediaQueries/linting/core.d.ts +5 -0
- package/dist/esm/mediaQueries/linting/core.d.ts.map +1 -0
- package/dist/esm/mediaQueries/linting/core.js +14 -0
- package/dist/esm/mediaQueries/linting/resolution.d.ts +3 -0
- package/dist/esm/mediaQueries/linting/resolution.d.ts.map +1 -0
- package/dist/esm/mediaQueries/linting/resolution.js +7 -0
- package/dist/esm/mediaQueries/linting.d.ts +4 -0
- package/dist/esm/mediaQueries/linting.d.ts.map +1 -0
- package/dist/esm/mediaQueries/linting.js +20 -0
- package/dist/esm/mediaQueries/mediaQueries.d.ts +19 -0
- package/dist/esm/mediaQueries/mediaQueries.d.ts.map +1 -0
- package/dist/esm/mediaQueries/mediaQueries.js +46 -0
- package/dist/esm/mediaQueries/modules/custom.d.ts +10 -0
- package/dist/esm/mediaQueries/modules/custom.d.ts.map +1 -0
- package/dist/esm/mediaQueries/modules/custom.js +22 -0
- package/dist/esm/mediaQueries/modules/dimensions.d.ts +17 -0
- package/dist/esm/mediaQueries/modules/dimensions.d.ts.map +1 -0
- package/dist/esm/mediaQueries/modules/dimensions.js +55 -0
- package/dist/esm/mediaQueries/modules/display.d.ts +9 -0
- package/dist/esm/mediaQueries/modules/display.d.ts.map +1 -0
- package/dist/esm/mediaQueries/modules/display.js +16 -0
- package/dist/esm/mediaQueries/modules/environment.d.ts +9 -0
- package/dist/esm/mediaQueries/modules/environment.d.ts.map +1 -0
- package/dist/esm/mediaQueries/modules/environment.js +16 -0
- package/dist/esm/mediaQueries/modules/index.d.ts +8 -0
- package/dist/esm/mediaQueries/modules/index.d.ts.map +1 -0
- package/dist/esm/mediaQueries/modules/index.js +7 -0
- package/dist/esm/mediaQueries/modules/interaction.d.ts +11 -0
- package/dist/esm/mediaQueries/modules/interaction.d.ts.map +1 -0
- package/dist/esm/mediaQueries/modules/interaction.js +22 -0
- package/dist/esm/mediaQueries/modules/preferences.d.ts +11 -0
- package/dist/esm/mediaQueries/modules/preferences.d.ts.map +1 -0
- package/dist/esm/mediaQueries/modules/preferences.js +22 -0
- package/dist/esm/mediaQueries/modules/resolution.d.ts +10 -0
- package/dist/esm/mediaQueries/modules/resolution.d.ts.map +1 -0
- package/dist/esm/mediaQueries/modules/resolution.js +25 -0
- package/dist/esm/mediaQueries/types.d.ts +117 -0
- package/dist/esm/mediaQueries/types.d.ts.map +1 -0
- package/dist/esm/mediaQueries/types.js +1 -0
- package/dist/esm/mediaQueries/validation.d.ts +14 -0
- package/dist/esm/mediaQueries/validation.d.ts.map +1 -0
- package/dist/esm/mediaQueries/validation.js +122 -0
- package/package.json +20 -9
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.validateResolutionValues = exports.validateAspectRatioValuesPositive = exports.validateMinMaxAspectRatio = exports.validateHeightValuesPositive = exports.validateMinMaxHeight = exports.validateWidthValuesPositive = exports.validateMinMaxWidth = exports.runMediaQueryValidation = void 0;
|
|
4
|
+
const helpers_1 = require("./helpers");
|
|
5
|
+
const core_1 = require("../core");
|
|
6
|
+
const toValidationResult = (error, fallback) => {
|
|
7
|
+
if (error instanceof Error && error.message)
|
|
8
|
+
return error.message;
|
|
9
|
+
return fallback;
|
|
10
|
+
};
|
|
11
|
+
const runMediaQueryValidation = (config, helpers, check, context, fallbackMessage = 'Invalid media query configuration') => {
|
|
12
|
+
if (!check)
|
|
13
|
+
return true;
|
|
14
|
+
try {
|
|
15
|
+
check(config);
|
|
16
|
+
return true;
|
|
17
|
+
}
|
|
18
|
+
catch (error) {
|
|
19
|
+
const result = toValidationResult(error, fallbackMessage);
|
|
20
|
+
return (0, helpers_1.applyMediaQueryValidation)(config, helpers, () => result, context);
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
exports.runMediaQueryValidation = runMediaQueryValidation;
|
|
24
|
+
const validateMinMaxWidth = (props) => {
|
|
25
|
+
if (!props.minWidth || !props.maxWidth)
|
|
26
|
+
return;
|
|
27
|
+
(0, core_1.assertMatchingUnits)(props.minWidth, props.maxWidth, 'mediaQueries.minMaxWidth');
|
|
28
|
+
(0, core_1.assertCondition)(props.minWidth.getValue() <= props.maxWidth.getValue(), 'minWidth must be less than or equal to maxWidth');
|
|
29
|
+
};
|
|
30
|
+
exports.validateMinMaxWidth = validateMinMaxWidth;
|
|
31
|
+
const validateWidthValuesPositive = (props) => {
|
|
32
|
+
const assertPositive = (value, label) => {
|
|
33
|
+
(0, core_1.assertCondition)(value.getValue() > 0, `${label} must be greater than 0`);
|
|
34
|
+
};
|
|
35
|
+
if (props.width) {
|
|
36
|
+
assertPositive(props.width, 'width');
|
|
37
|
+
}
|
|
38
|
+
if (props.minWidth) {
|
|
39
|
+
assertPositive(props.minWidth, 'minWidth');
|
|
40
|
+
}
|
|
41
|
+
if (props.maxWidth) {
|
|
42
|
+
assertPositive(props.maxWidth, 'maxWidth');
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
exports.validateWidthValuesPositive = validateWidthValuesPositive;
|
|
46
|
+
const validateMinMaxHeight = (props) => {
|
|
47
|
+
if (!props.minHeight || !props.maxHeight)
|
|
48
|
+
return;
|
|
49
|
+
(0, core_1.assertMatchingUnits)(props.minHeight, props.maxHeight, 'mediaQueries.minMaxHeight');
|
|
50
|
+
(0, core_1.assertCondition)(props.minHeight.getValue() <= props.maxHeight.getValue(), 'minHeight must be less than or equal to maxHeight');
|
|
51
|
+
};
|
|
52
|
+
exports.validateMinMaxHeight = validateMinMaxHeight;
|
|
53
|
+
const validateHeightValuesPositive = (props) => {
|
|
54
|
+
const assertPositive = (value, label) => {
|
|
55
|
+
(0, core_1.assertCondition)(value.getValue() > 0, `${label} must be greater than 0`);
|
|
56
|
+
};
|
|
57
|
+
if (props.height) {
|
|
58
|
+
assertPositive(props.height, 'height');
|
|
59
|
+
}
|
|
60
|
+
if (props.minHeight) {
|
|
61
|
+
assertPositive(props.minHeight, 'minHeight');
|
|
62
|
+
}
|
|
63
|
+
if (props.maxHeight) {
|
|
64
|
+
assertPositive(props.maxHeight, 'maxHeight');
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
exports.validateHeightValuesPositive = validateHeightValuesPositive;
|
|
68
|
+
const parseAspectRatio = (value) => {
|
|
69
|
+
if (value === undefined || value === null)
|
|
70
|
+
return null;
|
|
71
|
+
if (typeof value === 'number')
|
|
72
|
+
return Number.isFinite(value) ? value : null;
|
|
73
|
+
const trimmed = value.trim();
|
|
74
|
+
if (!trimmed)
|
|
75
|
+
return null;
|
|
76
|
+
if (trimmed.includes('/')) {
|
|
77
|
+
const [left, right] = trimmed.split('/');
|
|
78
|
+
if (left === undefined || right === undefined)
|
|
79
|
+
return null;
|
|
80
|
+
const numerator = Number(left.trim());
|
|
81
|
+
const denominator = Number(right.trim());
|
|
82
|
+
if (!Number.isFinite(numerator) || !Number.isFinite(denominator)) {
|
|
83
|
+
return null;
|
|
84
|
+
}
|
|
85
|
+
if (denominator === 0)
|
|
86
|
+
return null;
|
|
87
|
+
return numerator / denominator;
|
|
88
|
+
}
|
|
89
|
+
const parsed = Number(trimmed);
|
|
90
|
+
return Number.isFinite(parsed) ? parsed : null;
|
|
91
|
+
};
|
|
92
|
+
const validateMinMaxAspectRatio = (props) => {
|
|
93
|
+
if (!props.minAspectRatio || !props.maxAspectRatio)
|
|
94
|
+
return;
|
|
95
|
+
const minRatio = parseAspectRatio(props.minAspectRatio);
|
|
96
|
+
const maxRatio = parseAspectRatio(props.maxAspectRatio);
|
|
97
|
+
(0, core_1.assertCondition)(minRatio !== null && maxRatio !== null, 'aspectRatio values must be valid numbers or ratio strings');
|
|
98
|
+
(0, core_1.assertCondition)(minRatio <= maxRatio, 'minAspectRatio must be less than or equal to maxAspectRatio');
|
|
99
|
+
};
|
|
100
|
+
exports.validateMinMaxAspectRatio = validateMinMaxAspectRatio;
|
|
101
|
+
const validateAspectRatioValuesPositive = (props) => {
|
|
102
|
+
const assertValidPositive = (label, value) => {
|
|
103
|
+
(0, core_1.assertCondition)(value !== null && value > 0, `${label} must be a valid ratio greater than 0`);
|
|
104
|
+
};
|
|
105
|
+
if (props.aspectRatio !== undefined) {
|
|
106
|
+
assertValidPositive('aspectRatio', parseAspectRatio(props.aspectRatio));
|
|
107
|
+
}
|
|
108
|
+
if (props.minAspectRatio !== undefined) {
|
|
109
|
+
assertValidPositive('minAspectRatio', parseAspectRatio(props.minAspectRatio));
|
|
110
|
+
}
|
|
111
|
+
if (props.maxAspectRatio !== undefined) {
|
|
112
|
+
assertValidPositive('maxAspectRatio', parseAspectRatio(props.maxAspectRatio));
|
|
113
|
+
}
|
|
114
|
+
};
|
|
115
|
+
exports.validateAspectRatioValuesPositive = validateAspectRatioValuesPositive;
|
|
116
|
+
const validateResolutionValues = (props) => {
|
|
117
|
+
const assertPositive = (value, label) => {
|
|
118
|
+
(0, core_1.assertCondition)(value.getValue() > 0, `${label} must be greater than 0`);
|
|
119
|
+
};
|
|
120
|
+
if (props.resolutionValue) {
|
|
121
|
+
assertPositive(props.resolutionValue, 'resolution');
|
|
122
|
+
}
|
|
123
|
+
if (props.minResolution) {
|
|
124
|
+
assertPositive(props.minResolution, 'minResolution');
|
|
125
|
+
}
|
|
126
|
+
if (props.maxResolution) {
|
|
127
|
+
assertPositive(props.maxResolution, 'maxResolution');
|
|
128
|
+
}
|
|
129
|
+
if (props.minResolution && props.maxResolution) {
|
|
130
|
+
(0, core_1.assertMatchingUnits)(props.minResolution, props.maxResolution, 'mediaQueries.resolutionUnits');
|
|
131
|
+
}
|
|
132
|
+
};
|
|
133
|
+
exports.validateResolutionValues = validateResolutionValues;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { IMeasurement } from '../core';
|
|
2
|
+
type MediaQueryFeatureValue = string | number | IMeasurement;
|
|
3
|
+
type MediaQueryFeatureEmitter = (name: string, value: MediaQueryFeatureValue) => void;
|
|
4
|
+
export type MediaQueryInvalidValueMode = 'allow' | 'log' | 'throw';
|
|
5
|
+
export type MediaQueryLintingMode = 'allow' | 'log' | 'throw';
|
|
6
|
+
export type MediaQueryBuilderConfig = {
|
|
7
|
+
errorHandling?: {
|
|
8
|
+
invalidValueMode?: MediaQueryInvalidValueMode;
|
|
9
|
+
lintingMode?: MediaQueryLintingMode;
|
|
10
|
+
};
|
|
11
|
+
};
|
|
12
|
+
export interface MediaQueryBuilderHelpers {
|
|
13
|
+
addFeature: MediaQueryFeatureEmitter;
|
|
14
|
+
config: MediaQueryBuilderConfig;
|
|
15
|
+
}
|
|
16
|
+
export type MediaQueryValidationResult = boolean | string | null | undefined | {
|
|
17
|
+
valid: boolean;
|
|
18
|
+
message?: string;
|
|
19
|
+
};
|
|
20
|
+
export type MediaQueryValidator<TConfig> = (config: TConfig) => MediaQueryValidationResult;
|
|
21
|
+
export type MediaQueryExtensionHandler<TConfig> = (config: TConfig, helpers: MediaQueryBuilderHelpers) => void;
|
|
22
|
+
type MediaQueryBuilderOptions<TConfig> = {
|
|
23
|
+
emitBase: MediaQueryExtensionHandler<TConfig>;
|
|
24
|
+
emitExtensions?: MediaQueryExtensionHandler<TConfig>;
|
|
25
|
+
resolveType?: (config: TConfig) => 'all' | 'print' | 'screen' | undefined;
|
|
26
|
+
config?: MediaQueryBuilderConfig;
|
|
27
|
+
};
|
|
28
|
+
export declare const formatMediaQueryValue: (value: MediaQueryFeatureValue) => string;
|
|
29
|
+
export declare const buildMediaQueryStringFromParts: (mediaType: "all" | "print" | "screen", parts: string[]) => string;
|
|
30
|
+
export declare const createMediaQueryFeatureEmitter: (parts: string[]) => MediaQueryFeatureEmitter;
|
|
31
|
+
type MediaQueryFeatureEmitterOptions = {
|
|
32
|
+
emitted?: Set<string>;
|
|
33
|
+
lintingMode?: MediaQueryLintingMode;
|
|
34
|
+
};
|
|
35
|
+
export declare const createMediaQueryFeatureEmitterWithTracking: (parts: string[], options?: MediaQueryFeatureEmitterOptions) => MediaQueryFeatureEmitter;
|
|
36
|
+
export declare const createMediaQueryBuilder: <TConfig>(options: MediaQueryBuilderOptions<TConfig>) => (config: TConfig) => string;
|
|
37
|
+
export declare const applyMediaQueryValidation: <TConfig>(config: TConfig, helpers: MediaQueryBuilderHelpers, validator?: MediaQueryValidator<TConfig>, context?: string) => boolean;
|
|
38
|
+
export declare const buildMediaQueryFromFeatures: (features: Record<string, MediaQueryFeatureValue>, mediaType?: "all" | "print" | "screen") => string;
|
|
39
|
+
export {};
|
|
40
|
+
//# sourceMappingURL=helpers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../../src/mediaQueries/helpers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAG5C,KAAK,sBAAsB,GAAG,MAAM,GAAG,MAAM,GAAG,YAAY,CAAC;AAE7D,KAAK,wBAAwB,GAAG,CAC9B,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,sBAAsB,KAC1B,IAAI,CAAC;AAEV,MAAM,MAAM,0BAA0B,GAAG,OAAO,GAAG,KAAK,GAAG,OAAO,CAAC;AACnE,MAAM,MAAM,qBAAqB,GAAG,OAAO,GAAG,KAAK,GAAG,OAAO,CAAC;AAE9D,MAAM,MAAM,uBAAuB,GAAG;IACpC,aAAa,CAAC,EAAE;QACd,gBAAgB,CAAC,EAAE,0BAA0B,CAAC;QAC9C,WAAW,CAAC,EAAE,qBAAqB,CAAC;KACrC,CAAC;CACH,CAAC;AAEF,MAAM,WAAW,wBAAwB;IACvC,UAAU,EAAE,wBAAwB,CAAC;IACrC,MAAM,EAAE,uBAAuB,CAAC;CACjC;AAED,MAAM,MAAM,0BAA0B,GAClC,OAAO,GACP,MAAM,GACN,IAAI,GACJ,SAAS,GACT;IACE,KAAK,EAAE,OAAO,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB,CAAC;AAEN,MAAM,MAAM,mBAAmB,CAAC,OAAO,IAAI,CACzC,MAAM,EAAE,OAAO,KACZ,0BAA0B,CAAC;AAEhC,MAAM,MAAM,0BAA0B,CAAC,OAAO,IAAI,CAChD,MAAM,EAAE,OAAO,EACf,OAAO,EAAE,wBAAwB,KAC9B,IAAI,CAAC;AAEV,KAAK,wBAAwB,CAAC,OAAO,IAAI;IACvC,QAAQ,EAAE,0BAA0B,CAAC,OAAO,CAAC,CAAC;IAC9C,cAAc,CAAC,EAAE,0BAA0B,CAAC,OAAO,CAAC,CAAC;IACrD,WAAW,CAAC,EAAE,CAAC,MAAM,EAAE,OAAO,KAAK,KAAK,GAAG,OAAO,GAAG,QAAQ,GAAG,SAAS,CAAC;IAC1E,MAAM,CAAC,EAAE,uBAAuB,CAAC;CAClC,CAAC;AAEF,eAAO,MAAM,qBAAqB,GAChC,OAAO,sBAAsB,KAC5B,MAA6D,CAAC;AAEjE,eAAO,MAAM,8BAA8B,GACzC,WAAW,KAAK,GAAG,OAAO,GAAG,QAAQ,EACrC,OAAO,MAAM,EAAE,KACd,MAAgF,CAAC;AAEpF,eAAO,MAAM,8BAA8B,GACzC,OAAO,MAAM,EAAE,KACd,wBAGA,CAAC;AAEJ,KAAK,+BAA+B,GAAG;IACrC,OAAO,CAAC,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;IACtB,WAAW,CAAC,EAAE,qBAAqB,CAAC;CACrC,CAAC;AAEF,eAAO,MAAM,0CAA0C,GACrD,OAAO,MAAM,EAAE,EACf,UAAS,+BAAoC,KAC5C,wBAkBF,CAAC;AAEF,eAAO,MAAM,uBAAuB,GAAI,OAAO,EAC7C,SAAS,wBAAwB,CAAC,OAAO,CAAC,MAElC,QAAQ,OAAO,KAAG,MAiB3B,CAAC;AAaF,eAAO,MAAM,yBAAyB,GAAI,OAAO,EAC/C,QAAQ,OAAO,EACf,SAAS,wBAAwB,EACjC,YAAY,mBAAmB,CAAC,OAAO,CAAC,EACxC,UAAU,MAAM,KACf,OAqBF,CAAC;AAEF,eAAO,MAAM,2BAA2B,GACtC,UAAU,MAAM,CAAC,MAAM,EAAE,sBAAsB,CAAC,EAChD,YAAW,KAAK,GAAG,OAAO,GAAG,QAAmB,KAC/C,MAaF,CAAC"}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { hasCssMethod } from '../core';
|
|
2
|
+
export const formatMediaQueryValue = (value) => (hasCssMethod(value) ? value.css() : String(value));
|
|
3
|
+
export const buildMediaQueryStringFromParts = (mediaType, parts) => (parts.length ? `${mediaType} and ${parts.join(' and ')}` : mediaType);
|
|
4
|
+
export const createMediaQueryFeatureEmitter = (parts) => (name, value) => {
|
|
5
|
+
parts.push(`(${name}: ${formatMediaQueryValue(value)})`);
|
|
6
|
+
};
|
|
7
|
+
export const createMediaQueryFeatureEmitterWithTracking = (parts, options = {}) => {
|
|
8
|
+
const { emitted, lintingMode = 'throw' } = options;
|
|
9
|
+
return (name, value) => {
|
|
10
|
+
if (emitted === null || emitted === void 0 ? void 0 : emitted.has(name)) {
|
|
11
|
+
if (lintingMode === 'throw') {
|
|
12
|
+
throw new Error(`Media query feature "${name}" was emitted more than once.`);
|
|
13
|
+
}
|
|
14
|
+
if (lintingMode === 'log') {
|
|
15
|
+
console.warn(`Media query feature "${name}" was emitted more than once; using the latest value.`);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
emitted === null || emitted === void 0 ? void 0 : emitted.add(name);
|
|
19
|
+
parts.push(`(${name}: ${formatMediaQueryValue(value)})`);
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
export const createMediaQueryBuilder = (options) => {
|
|
23
|
+
return (config) => {
|
|
24
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
25
|
+
const parts = [];
|
|
26
|
+
const emittedFeatures = new Set();
|
|
27
|
+
const helpers = {
|
|
28
|
+
addFeature: createMediaQueryFeatureEmitterWithTracking(parts, {
|
|
29
|
+
emitted: emittedFeatures,
|
|
30
|
+
lintingMode: (_c = (_b = (_a = options.config) === null || _a === void 0 ? void 0 : _a.errorHandling) === null || _b === void 0 ? void 0 : _b.lintingMode) !== null && _c !== void 0 ? _c : 'throw',
|
|
31
|
+
}),
|
|
32
|
+
config: (_d = options.config) !== null && _d !== void 0 ? _d : {},
|
|
33
|
+
};
|
|
34
|
+
options.emitBase(config, helpers);
|
|
35
|
+
(_e = options.emitExtensions) === null || _e === void 0 ? void 0 : _e.call(options, config, helpers);
|
|
36
|
+
const mediaType = (_g = (_f = options.resolveType) === null || _f === void 0 ? void 0 : _f.call(options, config)) !== null && _g !== void 0 ? _g : 'screen';
|
|
37
|
+
return buildMediaQueryStringFromParts(mediaType, parts);
|
|
38
|
+
};
|
|
39
|
+
};
|
|
40
|
+
const normalizeValidationResult = (result) => {
|
|
41
|
+
if (result === undefined || result === null)
|
|
42
|
+
return { valid: true };
|
|
43
|
+
if (typeof result === 'boolean')
|
|
44
|
+
return { valid: result };
|
|
45
|
+
if (typeof result === 'string') {
|
|
46
|
+
return result ? { valid: false, message: result } : { valid: true };
|
|
47
|
+
}
|
|
48
|
+
return result;
|
|
49
|
+
};
|
|
50
|
+
export const applyMediaQueryValidation = (config, helpers, validator, context) => {
|
|
51
|
+
var _a, _b;
|
|
52
|
+
if (!validator)
|
|
53
|
+
return true;
|
|
54
|
+
const normalized = normalizeValidationResult(validator(config));
|
|
55
|
+
if (normalized.valid)
|
|
56
|
+
return true;
|
|
57
|
+
const mode = (_b = (_a = helpers.config.errorHandling) === null || _a === void 0 ? void 0 : _a.invalidValueMode) !== null && _b !== void 0 ? _b : 'throw';
|
|
58
|
+
if (mode === 'log') {
|
|
59
|
+
const suffix = normalized.message ? `: ${normalized.message}` : '';
|
|
60
|
+
const prefix = context
|
|
61
|
+
? `Media query ${context} validation failed`
|
|
62
|
+
: 'Media query validation failed';
|
|
63
|
+
console.warn(`${prefix}${suffix}`);
|
|
64
|
+
}
|
|
65
|
+
if (mode === 'allow')
|
|
66
|
+
return true;
|
|
67
|
+
if (mode === 'log')
|
|
68
|
+
return true;
|
|
69
|
+
const suffix = normalized.message ? `: ${normalized.message}` : '';
|
|
70
|
+
const prefix = context
|
|
71
|
+
? `Media query ${context} validation failed`
|
|
72
|
+
: 'Media query validation failed';
|
|
73
|
+
throw new Error(`${prefix}${suffix}`);
|
|
74
|
+
};
|
|
75
|
+
export const buildMediaQueryFromFeatures = (features, mediaType = 'screen') => {
|
|
76
|
+
const parts = [];
|
|
77
|
+
const addFeature = createMediaQueryFeatureEmitterWithTracking(parts, {
|
|
78
|
+
emitted: new Set(),
|
|
79
|
+
lintingMode: 'throw',
|
|
80
|
+
});
|
|
81
|
+
Object.entries(features).forEach(([name, value]) => {
|
|
82
|
+
if (value === undefined || value === null)
|
|
83
|
+
return;
|
|
84
|
+
addFeature(name, value);
|
|
85
|
+
});
|
|
86
|
+
return buildMediaQueryStringFromParts(mediaType, parts);
|
|
87
|
+
};
|
|
@@ -0,0 +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"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { IMediaQueryCore } from '../mediaQueries';
|
|
2
|
+
import type { IMediaQueryDimensions } from '../modules/dimensions';
|
|
3
|
+
export declare const lintWidthRedundancy: (props: IMediaQueryCore & IMediaQueryDimensions) => void;
|
|
4
|
+
export declare const lintHeightRedundancy: (props: IMediaQueryDimensions) => void;
|
|
5
|
+
//# sourceMappingURL=core.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"core.d.ts","sourceRoot":"","sources":["../../../../src/mediaQueries/linting/core.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AACvD,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,uBAAuB,CAAC;AAEnE,eAAO,MAAM,mBAAmB,GAC9B,OAAO,eAAe,GAAG,qBAAqB,KAC7C,IAOF,CAAC;AAEF,eAAO,MAAM,oBAAoB,GAC/B,OAAO,qBAAqB,KAC3B,IAOF,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export const lintWidthRedundancy = (props) => {
|
|
2
|
+
if (!props.width)
|
|
3
|
+
return;
|
|
4
|
+
if (props.minWidth || props.maxWidth) {
|
|
5
|
+
throw new Error('width should not be combined with minWidth or maxWidth');
|
|
6
|
+
}
|
|
7
|
+
};
|
|
8
|
+
export const lintHeightRedundancy = (props) => {
|
|
9
|
+
if (!props.height)
|
|
10
|
+
return;
|
|
11
|
+
if (props.minHeight || props.maxHeight) {
|
|
12
|
+
throw new Error('height should not be combined with minHeight or maxHeight');
|
|
13
|
+
}
|
|
14
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolution.d.ts","sourceRoot":"","sources":["../../../../src/mediaQueries/linting/resolution.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,uBAAuB,CAAC;AAExE,eAAO,MAAM,wBAAwB,GACnC,OAAO,0BAA0B,KAChC,IAOF,CAAC"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { MediaQueryBuilderHelpers } from './helpers';
|
|
2
|
+
export type MediaQueryLintCheck<TConfig> = (config: TConfig) => void;
|
|
3
|
+
export declare const runMediaQueryLint: <TConfig>(config: TConfig, helpers: MediaQueryBuilderHelpers, check?: MediaQueryLintCheck<TConfig>, message?: string) => boolean;
|
|
4
|
+
//# sourceMappingURL=linting.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"linting.d.ts","sourceRoot":"","sources":["../../../src/mediaQueries/linting.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,wBAAwB,EAEzB,MAAM,WAAW,CAAC;AAEnB,MAAM,MAAM,mBAAmB,CAAC,OAAO,IAAI,CAAC,MAAM,EAAE,OAAO,KAAK,IAAI,CAAC;AAErE,eAAO,MAAM,iBAAiB,GAAI,OAAO,EACvC,QAAQ,OAAO,EACf,SAAS,wBAAwB,EACjC,QAAQ,mBAAmB,CAAC,OAAO,CAAC,EACpC,gBAAmC,KAClC,OAiBF,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export const runMediaQueryLint = (config, helpers, check, message = 'Media query lint failed') => {
|
|
2
|
+
var _a, _b;
|
|
3
|
+
if (!check)
|
|
4
|
+
return true;
|
|
5
|
+
const mode = (_b = (_a = helpers.config.errorHandling) === null || _a === void 0 ? void 0 : _a.lintingMode) !== null && _b !== void 0 ? _b : 'allow';
|
|
6
|
+
if (mode === 'allow')
|
|
7
|
+
return true;
|
|
8
|
+
if (mode === 'log') {
|
|
9
|
+
try {
|
|
10
|
+
check(config);
|
|
11
|
+
return true;
|
|
12
|
+
}
|
|
13
|
+
catch {
|
|
14
|
+
console.warn(message);
|
|
15
|
+
return true;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
check(config);
|
|
19
|
+
return true;
|
|
20
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { IMeasurement } from "../core";
|
|
2
|
+
import type { ComplexStyleRule, StyleRule } from "./types";
|
|
3
|
+
import { IMediaQueryCustomFeatures, IMediaQueryDimensions, IMediaQueryDisplay, IMediaQueryEnvironment, IMediaQueryInteraction, IMediaQueryPreferences, IMediaQueryResolutionRange } from "./modules";
|
|
4
|
+
export interface IMediaQueryProps extends IMediaQueryCore, IMediaQueryDimensions, IMediaQueryResolutionRange, IMediaQueryInteraction, IMediaQueryPreferences, IMediaQueryDisplay, IMediaQueryEnvironment, IMediaQueryCustomFeatures {
|
|
5
|
+
}
|
|
6
|
+
export interface IMediaQueryCore {
|
|
7
|
+
type?: "all" | "print" | "screen";
|
|
8
|
+
minWidth?: IMeasurement;
|
|
9
|
+
maxWidth?: IMeasurement;
|
|
10
|
+
}
|
|
11
|
+
export interface IMediaQuery {
|
|
12
|
+
props: IMediaQueryProps;
|
|
13
|
+
styles: StyleRule;
|
|
14
|
+
}
|
|
15
|
+
export type IMediaQueries = Record<string, IMediaQueryProps>;
|
|
16
|
+
export type IMediaQueryStyles<T extends IMediaQueries> = Partial<Record<keyof T, StyleRule>>;
|
|
17
|
+
export declare const buildMediaQueryString: (config: IMediaQueryProps) => string;
|
|
18
|
+
export declare const makeMediaQueryStyle: <T extends IMediaQueries>(queries: T) => (stylesByQuery: IMediaQueryStyles<T>) => ComplexStyleRule;
|
|
19
|
+
//# sourceMappingURL=mediaQueries.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mediaQueries.d.ts","sourceRoot":"","sources":["../../../src/mediaQueries/mediaQueries.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAC5C,OAAO,KAAK,EAAE,gBAAgB,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAQ3D,OAAO,EAQL,yBAAyB,EACzB,qBAAqB,EACrB,kBAAkB,EAClB,sBAAsB,EACtB,sBAAsB,EACtB,sBAAsB,EACtB,0BAA0B,EAC3B,MAAM,WAAW,CAAC;AAEnB,MAAM,WAAW,gBACf,SAAQ,eAAe,EACrB,qBAAqB,EACrB,0BAA0B,EAC1B,sBAAsB,EACtB,sBAAsB,EACtB,kBAAkB,EAClB,sBAAsB,EACtB,yBAAyB;CAAG;AAEhC,MAAM,WAAW,eAAe;IAC9B,IAAI,CAAC,EAAE,KAAK,GAAG,OAAO,GAAG,QAAQ,CAAC;IAClC,QAAQ,CAAC,EAAE,YAAY,CAAC;IACxB,QAAQ,CAAC,EAAE,YAAY,CAAC;CACzB;AAED,MAAM,WAAW,WAAW;IAC1B,KAAK,EAAE,gBAAgB,CAAC;IACxB,MAAM,EAAE,SAAS,CAAC;CACnB;AAED,MAAM,MAAM,aAAa,GAAG,MAAM,CAAC,MAAM,EAAE,gBAAgB,CAAC,CAAC;AAE7D,MAAM,MAAM,iBAAiB,CAAC,CAAC,SAAS,aAAa,IAAI,OAAO,CAC9D,MAAM,CAAC,MAAM,CAAC,EAAE,SAAS,CAAC,CAC3B,CAAC;AAoDF,eAAO,MAAM,qBAAqB,sCAGhC,CAAC;AAEH,eAAO,MAAM,mBAAmB,GAC7B,CAAC,SAAS,aAAa,EAAE,SAAS,CAAC,MACnC,eAAe,iBAAiB,CAAC,CAAC,CAAC,KAAG,gBActC,CAAC"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { createMediaQueryBuilder } from "./helpers";
|
|
2
|
+
import { runMediaQueryValidation, validateMinMaxWidth, validateWidthValuesPositive, } from "./validation";
|
|
3
|
+
import { emitCustomFeatures, emitDimensionsFeatures, emitDisplayFeatures, emitEnvironmentFeatures, emitInteractionFeatures, emitPreferencesFeatures, emitResolutionFeatures, } from "./modules";
|
|
4
|
+
const emitCoreFeatures = (props, helpers) => {
|
|
5
|
+
if (!runMediaQueryValidation(props, helpers, validateMinMaxWidth, "core", "minWidth must be less than or equal to maxWidth")) {
|
|
6
|
+
return;
|
|
7
|
+
}
|
|
8
|
+
if (!runMediaQueryValidation(props, helpers, validateWidthValuesPositive, "core", "width values must be greater than 0")) {
|
|
9
|
+
return;
|
|
10
|
+
}
|
|
11
|
+
const { addFeature } = helpers;
|
|
12
|
+
if (props.minWidth) {
|
|
13
|
+
addFeature("min-width", props.minWidth);
|
|
14
|
+
}
|
|
15
|
+
if (props.maxWidth) {
|
|
16
|
+
addFeature("max-width", props.maxWidth);
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
const emitBaseFeatures = (props, helpers) => {
|
|
20
|
+
emitCoreFeatures(props, helpers);
|
|
21
|
+
emitDimensionsFeatures(props, helpers);
|
|
22
|
+
emitResolutionFeatures(props, helpers);
|
|
23
|
+
emitInteractionFeatures(props, helpers);
|
|
24
|
+
emitPreferencesFeatures(props, helpers);
|
|
25
|
+
emitDisplayFeatures(props, helpers);
|
|
26
|
+
emitEnvironmentFeatures(props, helpers);
|
|
27
|
+
emitCustomFeatures(props, helpers);
|
|
28
|
+
};
|
|
29
|
+
export const buildMediaQueryString = createMediaQueryBuilder({
|
|
30
|
+
emitBase: emitBaseFeatures,
|
|
31
|
+
resolveType: (props) => props.type,
|
|
32
|
+
});
|
|
33
|
+
export const makeMediaQueryStyle = (queries) => (stylesByQuery) => {
|
|
34
|
+
const result = {};
|
|
35
|
+
Object.keys(stylesByQuery).forEach((key) => {
|
|
36
|
+
const styles = stylesByQuery[key];
|
|
37
|
+
const props = queries[key];
|
|
38
|
+
if (!styles || !props)
|
|
39
|
+
return;
|
|
40
|
+
result[buildMediaQueryString(props)] = styles;
|
|
41
|
+
});
|
|
42
|
+
const mediaQuery = {
|
|
43
|
+
"@media": result,
|
|
44
|
+
};
|
|
45
|
+
return mediaQuery;
|
|
46
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { IMeasurement } from '../../core';
|
|
2
|
+
import type { MediaQueryBuilderHelpers, MediaQueryValidator } from '../helpers';
|
|
3
|
+
type MediaQueryFeatureValue = string | number | IMeasurement;
|
|
4
|
+
export interface IMediaQueryCustomFeatures {
|
|
5
|
+
customFeatures?: Record<string, MediaQueryFeatureValue>;
|
|
6
|
+
}
|
|
7
|
+
export type MediaQueryCustomFeaturesValidator = MediaQueryValidator<IMediaQueryCustomFeatures>;
|
|
8
|
+
export declare const emitCustomFeatures: (props: IMediaQueryCustomFeatures, helpers: MediaQueryBuilderHelpers, validate?: MediaQueryCustomFeaturesValidator) => void;
|
|
9
|
+
export {};
|
|
10
|
+
//# sourceMappingURL=custom.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"custom.d.ts","sourceRoot":"","sources":["../../../../src/mediaQueries/modules/custom.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAE/C,OAAO,KAAK,EACV,wBAAwB,EACxB,mBAAmB,EACpB,MAAM,YAAY,CAAC;AAGpB,KAAK,sBAAsB,GAAG,MAAM,GAAG,MAAM,GAAG,YAAY,CAAC;AAE7D,MAAM,WAAW,yBAAyB;IACxC,cAAc,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,sBAAsB,CAAC,CAAC;CACzD;AAED,MAAM,MAAM,iCAAiC,GAC3C,mBAAmB,CAAC,yBAAyB,CAAC,CAAC;AAEjD,eAAO,MAAM,kBAAkB,GAC7B,OAAO,yBAAyB,EAChC,SAAS,wBAAwB,EACjC,WAAW,iCAAiC,KAC3C,IAqBF,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { hasCssMethod } from '../../core';
|
|
2
|
+
import { applyMediaQueryValidation } from '../helpers';
|
|
3
|
+
export const emitCustomFeatures = (props, helpers, validate) => {
|
|
4
|
+
if (!applyMediaQueryValidation(props, helpers, validate, 'custom')) {
|
|
5
|
+
return;
|
|
6
|
+
}
|
|
7
|
+
const { addFeature } = helpers;
|
|
8
|
+
if (!props.customFeatures)
|
|
9
|
+
return;
|
|
10
|
+
Object.entries(props.customFeatures).forEach(([name, value]) => {
|
|
11
|
+
if (value === undefined || value === null)
|
|
12
|
+
return;
|
|
13
|
+
const trimmedName = name.trim();
|
|
14
|
+
if (!trimmedName) {
|
|
15
|
+
throw new Error('Custom feature name must be non-empty.');
|
|
16
|
+
}
|
|
17
|
+
if (typeof value === 'object' && !hasCssMethod(value)) {
|
|
18
|
+
throw new Error(`Custom feature "${trimmedName}" must be a primitive or a measurement.`);
|
|
19
|
+
}
|
|
20
|
+
addFeature(trimmedName, value);
|
|
21
|
+
});
|
|
22
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { IMeasurement } from '../../core';
|
|
2
|
+
import type { MediaQueryBuilderHelpers, MediaQueryValidator } from '../helpers';
|
|
3
|
+
type MediaQueryRatio = number | string;
|
|
4
|
+
export interface IMediaQueryDimensions {
|
|
5
|
+
width?: IMeasurement;
|
|
6
|
+
minHeight?: IMeasurement;
|
|
7
|
+
maxHeight?: IMeasurement;
|
|
8
|
+
height?: IMeasurement;
|
|
9
|
+
aspectRatio?: MediaQueryRatio;
|
|
10
|
+
minAspectRatio?: MediaQueryRatio;
|
|
11
|
+
maxAspectRatio?: MediaQueryRatio;
|
|
12
|
+
orientation?: 'landscape' | 'portrait';
|
|
13
|
+
}
|
|
14
|
+
export type MediaQueryDimensionsValidator = MediaQueryValidator<IMediaQueryDimensions>;
|
|
15
|
+
export declare const emitDimensionsFeatures: (props: IMediaQueryDimensions, helpers: MediaQueryBuilderHelpers, validate?: MediaQueryDimensionsValidator) => void;
|
|
16
|
+
export {};
|
|
17
|
+
//# sourceMappingURL=dimensions.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dimensions.d.ts","sourceRoot":"","sources":["../../../../src/mediaQueries/modules/dimensions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAC/C,OAAO,KAAK,EACV,wBAAwB,EACxB,mBAAmB,EACpB,MAAM,YAAY,CAAC;AAgBpB,KAAK,eAAe,GAAG,MAAM,GAAG,MAAM,CAAC;AAEvC,MAAM,WAAW,qBAAqB;IACpC,KAAK,CAAC,EAAE,YAAY,CAAC;IACrB,SAAS,CAAC,EAAE,YAAY,CAAC;IACzB,SAAS,CAAC,EAAE,YAAY,CAAC;IACzB,MAAM,CAAC,EAAE,YAAY,CAAC;IACtB,WAAW,CAAC,EAAE,eAAe,CAAC;IAC9B,cAAc,CAAC,EAAE,eAAe,CAAC;IACjC,cAAc,CAAC,EAAE,eAAe,CAAC;IACjC,WAAW,CAAC,EAAE,WAAW,GAAG,UAAU,CAAC;CACxC;AAED,MAAM,MAAM,6BAA6B,GACvC,mBAAmB,CAAC,qBAAqB,CAAC,CAAC;AAE7C,eAAO,MAAM,sBAAsB,GACjC,OAAO,qBAAqB,EAC5B,SAAS,wBAAwB,EACjC,WAAW,6BAA6B,KACvC,IA0GF,CAAC"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { applyMediaQueryValidation } from '../helpers';
|
|
2
|
+
import { runMediaQueryValidation, validateAspectRatioValuesPositive, validateHeightValuesPositive, validateMinMaxAspectRatio, validateMinMaxHeight, validateWidthValuesPositive, } from '../validation';
|
|
3
|
+
import { runMediaQueryLint } from '../linting';
|
|
4
|
+
import { lintHeightRedundancy, lintWidthRedundancy, } from '../linting/core';
|
|
5
|
+
export const emitDimensionsFeatures = (props, helpers, validate) => {
|
|
6
|
+
if (!runMediaQueryValidation(props, helpers, validateMinMaxHeight, 'dimensions', 'minHeight must be less than or equal to maxHeight')) {
|
|
7
|
+
return;
|
|
8
|
+
}
|
|
9
|
+
if (!runMediaQueryValidation(props, helpers, validateHeightValuesPositive, 'dimensions', 'height values must be greater than 0')) {
|
|
10
|
+
return;
|
|
11
|
+
}
|
|
12
|
+
if (!runMediaQueryLint(props, helpers, lintWidthRedundancy, 'width should not be combined with minWidth or maxWidth')) {
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
if (!runMediaQueryLint(props, helpers, lintHeightRedundancy, 'height should not be combined with minHeight or maxHeight')) {
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
if (!runMediaQueryValidation(props, helpers, validateWidthValuesPositive, 'dimensions', 'width values must be greater than 0')) {
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
if (!runMediaQueryValidation(props, helpers, validateMinMaxAspectRatio, 'dimensions', 'minAspectRatio must be less than or equal to maxAspectRatio')) {
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
if (!runMediaQueryValidation(props, helpers, validateAspectRatioValuesPositive, 'dimensions', 'aspect ratio values must be greater than 0')) {
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
if (!applyMediaQueryValidation(props, helpers, validate, 'dimensions')) {
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
const { addFeature } = helpers;
|
|
31
|
+
if (props.width) {
|
|
32
|
+
addFeature('width', props.width);
|
|
33
|
+
}
|
|
34
|
+
if (props.height) {
|
|
35
|
+
addFeature('height', props.height);
|
|
36
|
+
}
|
|
37
|
+
if (props.minHeight) {
|
|
38
|
+
addFeature('min-height', props.minHeight);
|
|
39
|
+
}
|
|
40
|
+
if (props.maxHeight) {
|
|
41
|
+
addFeature('max-height', props.maxHeight);
|
|
42
|
+
}
|
|
43
|
+
if (props.aspectRatio) {
|
|
44
|
+
addFeature('aspect-ratio', props.aspectRatio);
|
|
45
|
+
}
|
|
46
|
+
if (props.minAspectRatio) {
|
|
47
|
+
addFeature('min-aspect-ratio', props.minAspectRatio);
|
|
48
|
+
}
|
|
49
|
+
if (props.maxAspectRatio) {
|
|
50
|
+
addFeature('max-aspect-ratio', props.maxAspectRatio);
|
|
51
|
+
}
|
|
52
|
+
if (props.orientation) {
|
|
53
|
+
addFeature('orientation', props.orientation);
|
|
54
|
+
}
|
|
55
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { MediaQueryBuilderHelpers, MediaQueryValidator } from '../helpers';
|
|
2
|
+
export interface IMediaQueryDisplay {
|
|
3
|
+
colorGamut?: 'srgb' | 'p3' | 'rec2020';
|
|
4
|
+
dynamicRange?: 'standard' | 'high';
|
|
5
|
+
invertedColors?: 'none' | 'inverted';
|
|
6
|
+
}
|
|
7
|
+
export type MediaQueryDisplayValidator = MediaQueryValidator<IMediaQueryDisplay>;
|
|
8
|
+
export declare const emitDisplayFeatures: (props: IMediaQueryDisplay, helpers: MediaQueryBuilderHelpers, validate?: MediaQueryDisplayValidator) => void;
|
|
9
|
+
//# sourceMappingURL=display.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"display.d.ts","sourceRoot":"","sources":["../../../../src/mediaQueries/modules/display.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,wBAAwB,EACxB,mBAAmB,EACpB,MAAM,YAAY,CAAC;AAGpB,MAAM,WAAW,kBAAkB;IACjC,UAAU,CAAC,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC;IACvC,YAAY,CAAC,EAAE,UAAU,GAAG,MAAM,CAAC;IACnC,cAAc,CAAC,EAAE,MAAM,GAAG,UAAU,CAAC;CACtC;AAED,MAAM,MAAM,0BAA0B,GACpC,mBAAmB,CAAC,kBAAkB,CAAC,CAAC;AAE1C,eAAO,MAAM,mBAAmB,GAC9B,OAAO,kBAAkB,EACzB,SAAS,wBAAwB,EACjC,WAAW,0BAA0B,KACpC,IAgBF,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { applyMediaQueryValidation } from '../helpers';
|
|
2
|
+
export const emitDisplayFeatures = (props, helpers, validate) => {
|
|
3
|
+
if (!applyMediaQueryValidation(props, helpers, validate, 'display')) {
|
|
4
|
+
return;
|
|
5
|
+
}
|
|
6
|
+
const { addFeature } = helpers;
|
|
7
|
+
if (props.colorGamut) {
|
|
8
|
+
addFeature('color-gamut', props.colorGamut);
|
|
9
|
+
}
|
|
10
|
+
if (props.dynamicRange) {
|
|
11
|
+
addFeature('dynamic-range', props.dynamicRange);
|
|
12
|
+
}
|
|
13
|
+
if (props.invertedColors) {
|
|
14
|
+
addFeature('inverted-colors', props.invertedColors);
|
|
15
|
+
}
|
|
16
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { MediaQueryBuilderHelpers, MediaQueryValidator } from '../helpers';
|
|
2
|
+
export interface IMediaQueryEnvironment {
|
|
3
|
+
scripting?: 'none' | 'initial-only' | 'enabled';
|
|
4
|
+
overflowBlock?: 'none' | 'scroll' | 'paged';
|
|
5
|
+
overflowInline?: 'none' | 'scroll';
|
|
6
|
+
}
|
|
7
|
+
export type MediaQueryEnvironmentValidator = MediaQueryValidator<IMediaQueryEnvironment>;
|
|
8
|
+
export declare const emitEnvironmentFeatures: (props: IMediaQueryEnvironment, helpers: MediaQueryBuilderHelpers, validate?: MediaQueryEnvironmentValidator) => void;
|
|
9
|
+
//# sourceMappingURL=environment.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"environment.d.ts","sourceRoot":"","sources":["../../../../src/mediaQueries/modules/environment.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,wBAAwB,EACxB,mBAAmB,EACpB,MAAM,YAAY,CAAC;AAGpB,MAAM,WAAW,sBAAsB;IACrC,SAAS,CAAC,EAAE,MAAM,GAAG,cAAc,GAAG,SAAS,CAAC;IAChD,aAAa,CAAC,EAAE,MAAM,GAAG,QAAQ,GAAG,OAAO,CAAC;IAC5C,cAAc,CAAC,EAAE,MAAM,GAAG,QAAQ,CAAC;CACpC;AAED,MAAM,MAAM,8BAA8B,GACxC,mBAAmB,CAAC,sBAAsB,CAAC,CAAC;AAE9C,eAAO,MAAM,uBAAuB,GAClC,OAAO,sBAAsB,EAC7B,SAAS,wBAAwB,EACjC,WAAW,8BAA8B,KACxC,IAkBF,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { applyMediaQueryValidation } from '../helpers';
|
|
2
|
+
export const emitEnvironmentFeatures = (props, helpers, validate) => {
|
|
3
|
+
if (!applyMediaQueryValidation(props, helpers, validate, 'environment')) {
|
|
4
|
+
return;
|
|
5
|
+
}
|
|
6
|
+
const { addFeature } = helpers;
|
|
7
|
+
if (props.scripting) {
|
|
8
|
+
addFeature('scripting', props.scripting);
|
|
9
|
+
}
|
|
10
|
+
if (props.overflowBlock) {
|
|
11
|
+
addFeature('overflow-block', props.overflowBlock);
|
|
12
|
+
}
|
|
13
|
+
if (props.overflowInline) {
|
|
14
|
+
addFeature('overflow-inline', props.overflowInline);
|
|
15
|
+
}
|
|
16
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/mediaQueries/modules/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,cAAc,CAAC;AAC7B,cAAc,WAAW,CAAC;AAC1B,cAAc,eAAe,CAAC;AAC9B,cAAc,eAAe,CAAC;AAC9B,cAAc,eAAe,CAAC;AAC9B,cAAc,cAAc,CAAC"}
|