@ankhorage/rules-design 0.3.1 → 0.3.3
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 +1 -1
- package/dist/features/color/colorObservationValues.d.ts +7 -0
- package/dist/features/color/colorObservationValues.js +9 -0
- package/dist/features/color/createColorPolicyRules.d.ts +6 -0
- package/dist/features/color/createColorPolicyRules.js +138 -0
- package/dist/features/color/createColorRuleSet.d.ts +6 -0
- package/dist/features/color/createColorRuleSet.js +175 -0
- package/dist/features/color/evaluateColorPolicyObservation.d.ts +6 -0
- package/dist/features/color/evaluateColorPolicyObservation.js +148 -0
- package/dist/features/color/isColorRulePolicy.d.ts +3 -0
- package/dist/features/color/isColorRulePolicy.js +84 -0
- package/dist/features/media/createMediaRuleSet.d.ts +12 -0
- package/dist/features/media/createMediaRuleSet.js +98 -0
- package/dist/features/media/evaluateMediaApplicability.d.ts +3 -0
- package/dist/features/media/evaluateMediaApplicability.js +64 -0
- package/dist/features/media/evaluateMediaAssessment.d.ts +14 -0
- package/dist/features/media/evaluateMediaAssessment.js +177 -0
- package/dist/features/media/mediaRuleDefinitions.d.ts +7 -0
- package/dist/features/media/mediaRuleDefinitions.js +17 -0
- package/dist/features/responsive/createResponsiveRules.d.ts +4 -0
- package/dist/features/responsive/createResponsiveRules.js +197 -0
- package/dist/features/responsive/evaluateResponsiveOrder.d.ts +3 -0
- package/dist/features/responsive/evaluateResponsiveOrder.js +33 -0
- package/dist/features/responsive/isContainedInResponsiveBounds.d.ts +3 -0
- package/dist/features/responsive/isContainedInResponsiveBounds.js +7 -0
- package/dist/features/responsive/parseResponsiveMatrix.d.ts +3 -0
- package/dist/features/responsive/parseResponsiveMatrix.js +146 -0
- package/dist/features/responsive/responsiveElementsOfKind.d.ts +3 -0
- package/dist/features/responsive/responsiveElementsOfKind.js +8 -0
- package/dist/features/responsive/selectResponsiveFact.d.ts +10 -0
- package/dist/features/responsive/selectResponsiveFact.js +12 -0
- package/dist/types/color.d.ts +25 -0
- package/dist/types/color.js +0 -0
- package/dist/types/responsive.d.ts +45 -0
- package/dist/types/responsive.js +0 -0
- package/package.json +1 -1
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
import { isRecord } from '@ankhorage/utility/object';
|
|
2
|
+
/*** Parses the serializable responsive fact payload without assuming host runtime objects. */
|
|
3
|
+
export function parseResponsiveMatrix(value) {
|
|
4
|
+
if (!isRecord(value))
|
|
5
|
+
return null;
|
|
6
|
+
const { requiredBreakpointIds, requiredOrientations, viewports } = value;
|
|
7
|
+
const parsedBreakpoints = parseStrings(requiredBreakpointIds);
|
|
8
|
+
const parsedOrientations = parseOrientations(requiredOrientations);
|
|
9
|
+
const parsedViewports = parseViewports(viewports);
|
|
10
|
+
return parsedBreakpoints === null || parsedOrientations === null || parsedViewports === null
|
|
11
|
+
? null
|
|
12
|
+
: {
|
|
13
|
+
requiredBreakpointIds: parsedBreakpoints,
|
|
14
|
+
requiredOrientations: parsedOrientations,
|
|
15
|
+
viewports: parsedViewports,
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
/*** Parses the measured viewport collection from a serializable fact payload. */
|
|
19
|
+
function parseViewports(value) {
|
|
20
|
+
if (!Array.isArray(value))
|
|
21
|
+
return null;
|
|
22
|
+
const viewports = value.map(parseViewport);
|
|
23
|
+
return viewports.every(isViewport) ? viewports : null;
|
|
24
|
+
}
|
|
25
|
+
/*** Checks whether one parsed value is a complete responsive viewport. */
|
|
26
|
+
function isViewport(value) {
|
|
27
|
+
return value !== null;
|
|
28
|
+
}
|
|
29
|
+
/*** Parses one measured viewport while retaining only explicit responsive facts. */
|
|
30
|
+
function parseViewport(value) {
|
|
31
|
+
if (!isRecord(value) || !isRecord(value.layout))
|
|
32
|
+
return null;
|
|
33
|
+
const { elements, id, orientation, size, zoom } = value;
|
|
34
|
+
const { renderedWidth, scrollWidth } = value.layout;
|
|
35
|
+
const parsedElements = parseElements(elements);
|
|
36
|
+
return typeof id !== 'string' ||
|
|
37
|
+
!isOrientation(orientation) ||
|
|
38
|
+
!isPositiveFiniteNumber(zoom) ||
|
|
39
|
+
!isDimensions(size) ||
|
|
40
|
+
!isNonNegativeFiniteNumber(renderedWidth) ||
|
|
41
|
+
!isNonNegativeFiniteNumber(scrollWidth) ||
|
|
42
|
+
parsedElements === null
|
|
43
|
+
? null
|
|
44
|
+
: {
|
|
45
|
+
elements: parsedElements,
|
|
46
|
+
id,
|
|
47
|
+
layout: { renderedWidth, scrollWidth },
|
|
48
|
+
orientation,
|
|
49
|
+
size,
|
|
50
|
+
zoom,
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
/*** Parses the responsive element measurements from one viewport. */
|
|
54
|
+
function parseElements(value) {
|
|
55
|
+
if (!Array.isArray(value))
|
|
56
|
+
return null;
|
|
57
|
+
const elements = value.map(parseElement);
|
|
58
|
+
return elements.every(isElement) ? elements : null;
|
|
59
|
+
}
|
|
60
|
+
/*** Checks whether one parsed value is a complete responsive element. */
|
|
61
|
+
function isElement(value) {
|
|
62
|
+
return value !== null;
|
|
63
|
+
}
|
|
64
|
+
/*** Parses one measured text, control, or image element. */
|
|
65
|
+
function parseElement(value) {
|
|
66
|
+
if (!isRecord(value) || !isRecord(value.bounds))
|
|
67
|
+
return null;
|
|
68
|
+
const { fixedSize, focalPointBounds, id, kind, readingOrder, textLineCount, visualOrder } = value;
|
|
69
|
+
return typeof id !== 'string' ||
|
|
70
|
+
!isElementKind(kind) ||
|
|
71
|
+
!isBounds(value.bounds) ||
|
|
72
|
+
!isNullableDimensions(fixedSize) ||
|
|
73
|
+
!isNullableBounds(focalPointBounds) ||
|
|
74
|
+
!isNullableFiniteNumber(readingOrder) ||
|
|
75
|
+
!isNullablePositiveInteger(textLineCount) ||
|
|
76
|
+
!isNullablePositiveFiniteNumber(value.textUnwrappedWidth) ||
|
|
77
|
+
!isNullableFiniteNumber(visualOrder)
|
|
78
|
+
? null
|
|
79
|
+
: {
|
|
80
|
+
bounds: value.bounds,
|
|
81
|
+
fixedSize,
|
|
82
|
+
focalPointBounds,
|
|
83
|
+
id,
|
|
84
|
+
kind,
|
|
85
|
+
readingOrder,
|
|
86
|
+
textLineCount,
|
|
87
|
+
textUnwrappedWidth: value.textUnwrappedWidth,
|
|
88
|
+
visualOrder,
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
/*** Parses a serializable list of identifier strings. */
|
|
92
|
+
function parseStrings(value) {
|
|
93
|
+
return Array.isArray(value) && value.every((item) => typeof item === 'string') ? value : null;
|
|
94
|
+
}
|
|
95
|
+
/*** Parses the declared orientation coverage set from normalized facts. */
|
|
96
|
+
function parseOrientations(value) {
|
|
97
|
+
return Array.isArray(value) && value.every(isOrientation) ? value : null;
|
|
98
|
+
}
|
|
99
|
+
/*** Checks the two portable orientation values accepted by the responsive fact contract. */
|
|
100
|
+
function isOrientation(value) {
|
|
101
|
+
return value === 'landscape' || value === 'portrait';
|
|
102
|
+
}
|
|
103
|
+
/*** Checks the semantic element kinds evaluated by this responsive family. */
|
|
104
|
+
function isElementKind(value) {
|
|
105
|
+
return value === 'control' || value === 'image' || value === 'text';
|
|
106
|
+
}
|
|
107
|
+
/*** Checks an optional numeric ordering fact whose unknown state is explicit. */
|
|
108
|
+
function isNullableFiniteNumber(value) {
|
|
109
|
+
return value === null || isFiniteNumber(value);
|
|
110
|
+
}
|
|
111
|
+
/*** Checks finite, positive viewport or fixed dimensions. */
|
|
112
|
+
function isDimensions(value) {
|
|
113
|
+
return (isRecord(value) && isPositiveFiniteNumber(value.width) && isPositiveFiniteNumber(value.height));
|
|
114
|
+
}
|
|
115
|
+
/*** Checks finite element or focal-point geometry with a positive rendered area. */
|
|
116
|
+
function isBounds(value) {
|
|
117
|
+
return (isDimensions(value) && isRecord(value) && isFiniteNumber(value.x) && isFiniteNumber(value.y));
|
|
118
|
+
}
|
|
119
|
+
/*** Checks an explicitly absent or complete fixed-size measurement. */
|
|
120
|
+
function isNullableDimensions(value) {
|
|
121
|
+
return value === null || isDimensions(value);
|
|
122
|
+
}
|
|
123
|
+
/*** Checks an explicitly absent or complete focal-point geometry measurement. */
|
|
124
|
+
function isNullableBounds(value) {
|
|
125
|
+
return value === null || isBounds(value);
|
|
126
|
+
}
|
|
127
|
+
/*** Checks a finite numeric measurement. */
|
|
128
|
+
function isFiniteNumber(value) {
|
|
129
|
+
return typeof value === 'number' && Number.isFinite(value);
|
|
130
|
+
}
|
|
131
|
+
/*** Checks a finite measurement that cannot be negative. */
|
|
132
|
+
function isNonNegativeFiniteNumber(value) {
|
|
133
|
+
return isFiniteNumber(value) && value >= 0;
|
|
134
|
+
}
|
|
135
|
+
/*** Checks a finite measurement that must describe a non-zero dimension or zoom. */
|
|
136
|
+
function isPositiveFiniteNumber(value) {
|
|
137
|
+
return isFiniteNumber(value) && value > 0;
|
|
138
|
+
}
|
|
139
|
+
/*** Checks an explicitly absent or positive whole line-count measurement. */
|
|
140
|
+
function isNullablePositiveInteger(value) {
|
|
141
|
+
return value === null || (isFiniteNumber(value) && Number.isInteger(value) && value > 0);
|
|
142
|
+
}
|
|
143
|
+
/*** Checks an explicitly absent or finite positive intrinsic inline-size measurement. */
|
|
144
|
+
function isNullablePositiveFiniteNumber(value) {
|
|
145
|
+
return value === null || isPositiveFiniteNumber(value);
|
|
146
|
+
}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { ResponsiveElement, ResponsiveMatrix } from '../../types/responsive';
|
|
2
|
+
/*** Returns all normalized measurements for one semantic element kind. */
|
|
3
|
+
export declare function responsiveElementsOfKind(matrix: ResponsiveMatrix, kind: ResponsiveElement['kind']): readonly ResponsiveElement[];
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/*** Returns all normalized measurements for one semantic element kind. */
|
|
2
|
+
export function responsiveElementsOfKind(matrix, kind) {
|
|
3
|
+
return allResponsiveElements(matrix).filter((element) => element.kind === kind);
|
|
4
|
+
}
|
|
5
|
+
/*** Flattens measured viewport elements without mutating their fact data. */
|
|
6
|
+
function allResponsiveElements(matrix) {
|
|
7
|
+
return matrix.viewports.flatMap((viewport) => viewport.elements);
|
|
8
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { FactEnvelope } from '@ankhorage/contracts/rules';
|
|
2
|
+
import type { RuleScope } from '@ankhorage/rules';
|
|
3
|
+
type AvailableResponsiveFact = Extract<FactEnvelope, {
|
|
4
|
+
readonly status: 'available';
|
|
5
|
+
}> & {
|
|
6
|
+
readonly kind: 'design.responsive.viewport-matrix';
|
|
7
|
+
};
|
|
8
|
+
/*** Selects exactly one available responsive matrix fact at the active Rules scope. */
|
|
9
|
+
export declare function selectResponsiveFact(facts: readonly FactEnvelope[], scope: RuleScope): AvailableResponsiveFact | null;
|
|
10
|
+
export {};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/*** Selects exactly one available responsive matrix fact at the active Rules scope. */
|
|
2
|
+
export function selectResponsiveFact(facts, scope) {
|
|
3
|
+
const matches = facts.filter((fact) => fact.kind === 'design.responsive.viewport-matrix' &&
|
|
4
|
+
fact.scope.id === scope.id &&
|
|
5
|
+
fact.scope.kind === scope.kind);
|
|
6
|
+
const [fact] = matches;
|
|
7
|
+
return matches.length === 1 && isAvailableResponsiveFact(fact) ? fact : null;
|
|
8
|
+
}
|
|
9
|
+
/*** Identifies the one scoped responsive matrix that can be evaluated. */
|
|
10
|
+
function isAvailableResponsiveFact(fact) {
|
|
11
|
+
return fact?.status === 'available' && fact.kind === 'design.responsive.viewport-matrix';
|
|
12
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/*** Identifies one frozen atomic Color policy rule. */
|
|
2
|
+
export type ColorPolicyRuleId = 'design.color.syntax-valid' | 'design.color.token-exists' | 'design.color.token-allowed' | 'design.color.semantic-role' | 'design.color.literal-drift' | 'design.color.ramp-consistency' | 'design.color.alpha-composition' | 'design.color.surface-role' | 'design.color.hover-state' | 'design.color.active-state' | 'design.color.disabled-state' | 'design.color.theme-coverage';
|
|
3
|
+
type ColorState = 'active' | 'disabled' | 'hover';
|
|
4
|
+
type ColorRole = 'accent' | 'base' | 'secondary';
|
|
5
|
+
type RoleValues = Readonly<Record<ColorRole, number>>;
|
|
6
|
+
/*** Configures trusted semantic acceptance and coverage policy for frozen Color rules. */
|
|
7
|
+
export interface ColorRulePolicy {
|
|
8
|
+
readonly alphaCompositions: Readonly<Record<string, Readonly<Record<string, string>>>>;
|
|
9
|
+
readonly allowedColorSyntaxes: readonly string[];
|
|
10
|
+
readonly allowedTokens: readonly string[];
|
|
11
|
+
readonly canonicalLiterals: Readonly<Record<string, string>>;
|
|
12
|
+
readonly knownTokens: readonly string[];
|
|
13
|
+
readonly rampTokens: Readonly<Record<string, readonly string[]>>;
|
|
14
|
+
readonly requiredBreakpointIds: readonly string[];
|
|
15
|
+
readonly requiredScopes: readonly ('page' | 'scroll-sample' | 'viewport')[];
|
|
16
|
+
readonly requiredThemeIds: readonly string[];
|
|
17
|
+
readonly roleTargets: RoleValues;
|
|
18
|
+
readonly roleTolerances: RoleValues;
|
|
19
|
+
readonly semanticRoleTokens: Readonly<Record<string, readonly string[]>>;
|
|
20
|
+
readonly stateTokens: Readonly<Record<ColorState, Readonly<Record<string, string>>>>;
|
|
21
|
+
readonly surfaceRoleTokens: Readonly<Record<string, readonly string[]>>;
|
|
22
|
+
readonly themeTokens: Readonly<Record<string, readonly string[]>>;
|
|
23
|
+
readonly version: number;
|
|
24
|
+
}
|
|
25
|
+
export {};
|
|
File without changes
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import type { FactEnvelope } from '@ankhorage/contracts/rules';
|
|
2
|
+
export interface ResponsiveDesignContext {
|
|
3
|
+
readonly facts: readonly FactEnvelope[];
|
|
4
|
+
}
|
|
5
|
+
/*** One deterministic Responsive rule result derived from normalized measurements. */
|
|
6
|
+
export interface ResponsiveEvaluation {
|
|
7
|
+
readonly failingIds: readonly string[];
|
|
8
|
+
readonly message: string;
|
|
9
|
+
readonly status: 'FAIL' | 'INCOMPLETE' | 'PASS';
|
|
10
|
+
}
|
|
11
|
+
export interface ResponsiveMatrix {
|
|
12
|
+
readonly requiredBreakpointIds: readonly string[];
|
|
13
|
+
readonly requiredOrientations: readonly ('landscape' | 'portrait')[];
|
|
14
|
+
readonly viewports: readonly ResponsiveViewport[];
|
|
15
|
+
}
|
|
16
|
+
export interface ResponsiveViewport {
|
|
17
|
+
readonly elements: readonly ResponsiveElement[];
|
|
18
|
+
readonly id: string;
|
|
19
|
+
readonly layout: {
|
|
20
|
+
readonly renderedWidth: number;
|
|
21
|
+
readonly scrollWidth: number;
|
|
22
|
+
};
|
|
23
|
+
readonly orientation: 'landscape' | 'portrait';
|
|
24
|
+
readonly size: ResponsiveDimensions;
|
|
25
|
+
readonly zoom: number;
|
|
26
|
+
}
|
|
27
|
+
export interface ResponsiveElement {
|
|
28
|
+
readonly bounds: ResponsiveBounds;
|
|
29
|
+
readonly fixedSize: ResponsiveDimensions | null;
|
|
30
|
+
readonly focalPointBounds: ResponsiveBounds | null;
|
|
31
|
+
readonly id: string;
|
|
32
|
+
readonly kind: 'control' | 'image' | 'text';
|
|
33
|
+
readonly readingOrder: number | null;
|
|
34
|
+
readonly textLineCount: number | null;
|
|
35
|
+
readonly textUnwrappedWidth: number | null;
|
|
36
|
+
readonly visualOrder: number | null;
|
|
37
|
+
}
|
|
38
|
+
export interface ResponsiveBounds extends ResponsiveDimensions {
|
|
39
|
+
readonly x: number;
|
|
40
|
+
readonly y: number;
|
|
41
|
+
}
|
|
42
|
+
export interface ResponsiveDimensions {
|
|
43
|
+
readonly height: number;
|
|
44
|
+
readonly width: number;
|
|
45
|
+
}
|
|
File without changes
|