Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ Before pushing a change to `packages/extract/**` or to a plugin (`packages/vite-
| the CSS vocabulary: `@webref/css`, `web-features` or `csstype` (`css-keywords.ts --write` also regenerates `packages/core/src/types/specification-properties.ts`) | `node packages/extract/scripts/css-keywords.ts --write`, then the `packages/core/src/**` and `extractor/src/**` rows |
| `ANIMUS_LAYERS` in `packages/extract/pipeline/assemble-stylesheet.ts` (`node packages/extract/scripts/layer-order.ts --write` regenerates `layer_order.json`) | the `extractor/src/**` row |
| `packages/extract/scripts/node-builtins.ts` (`--write`, under Node 24, regenerates `node_builtins.json`; rerun it when the pinned Node major changes) | `node packages/extract/scripts/node-builtins.ts --check`, then the `extractor/src/**` row |
| `packages/extract/scripts/css-support.ts`, or a `web-features` or `@webref/css` update (`node packages/extract/scripts/css-support.ts --write` regenerates `packages/extract/pipeline/css-support-table.ts`) | `node packages/extract/scripts/css-support.ts --check`, then the `packages/extract/pipeline/**` row |
| `packages/extract/crates/system-loader/**` | the `extractor/src/**` row |
| `packages/extract/crates/extractor/Cargo.toml` | `vp run verify:clippy && vp run verify:hygiene:rust && vp run verify:unit:rust` |
| `packages/extract/pipeline/**` | `vp run verify:compile && vp run verify:unit:ts && vp run verify:canary && vp run build:ts && vp run verify:types && vp run verify:integration` |
Expand Down
53 changes: 53 additions & 0 deletions packages/_integration/__tests__/target-support.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import {
unsupportedFeatures,
withoutLoweredFeatures,
} from '@animus-ui/extract/pipeline';
import { expect, test } from 'vitest';

import { analyzeProject } from './run-pipeline';

import type {
LightningTargets,
ManifestDiagnostic,
} from '@animus-ui/extract/pipeline';

const path = 'fixtures/target-support.tsx';
const source = `import { ds } from './setup';
export const Tip = ds
.styles({
anchorName: '--tip',
'@supports (position-anchor: --tip)': { positionAnchor: '--tip' },
})
.asElement('div');
export const App = () => <Tip />;
`;

function reported(targets: LightningTargets): ManifestDiagnostic[] {
const manifest = JSON.parse(
analyzeProject(JSON.stringify([{ path, source }]), {
analysisContextJson: JSON.stringify({
unsupportedFeatures: Object.fromEntries(unsupportedFeatures(targets)),
}),
})
) as { diagnostics: ManifestDiagnostic[] };
return withoutLoweredFeatures(manifest.diagnostics, {
targets,
features: {},
}).filter((d) => d.code === 'animus.style.unsupported-feature');
}

test('a property the targets lack is reported at the property, unless the targets support it or it sits inside a matching @supports', () => {
const lacking = reported({ safari: (16 << 16) | (4 << 8) });
expect(lacking).toHaveLength(1);
expect(lacking[0]).toMatchObject({
file: path,
component: 'Tip',
property: 'anchor-name',
reason: 'unsupported-property',
line: 4,
column: 17,
});
expect(lacking[0]!.message).toContain('safari 16.4');

expect(reported({ chrome: 130 << 16 })).toEqual([]);
});
6 changes: 6 additions & 0 deletions packages/core/src/binding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ export type {
StripIndex,
VariantProps,
} from './types/class-props.js';
export type {
ContractTagMatches,
ContractValues,
ExactContractRule,
VariantOptionMap,
} from './types/contract.js';
export type {
AdmittedNames,
StylingNames,
Expand Down
5 changes: 5 additions & 0 deletions packages/core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,11 @@ export type {
BuilderClassProps,
BuilderClassResolver,
} from './types/class-props.js';
export type {
ContractRequirement,
ContractRule,
ContractRuleEntry,
} from './types/contract.js';
export {
type Assign,
type AssignValueIfUnmergable,
Expand Down
67 changes: 67 additions & 0 deletions packages/core/src/types/contract.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import type { StripIndex } from './class-props';
import type { VariantKeyOf } from './config';

export interface ContractRequirement {
readonly attrs?: readonly string[];
readonly anyAttr?: readonly string[];
}

export interface ContractRule<
VMap = Readonly<Record<string, string>>,
StateKeys extends string = string,
> {
readonly when?: {
readonly [K in keyof VMap & string]?: VMap[K] | readonly VMap[K][];
};
readonly whenTag?: string | readonly string[];
readonly attrs?: Readonly<Record<string, string>>;
readonly require?: ContractRequirement;
readonly dischargedByState?: readonly StateKeys[];
}

export interface ContractRuleEntry {
readonly when?: Readonly<
Record<string, string | readonly string[] | undefined>
>;
readonly whenTag?: string | readonly string[];
readonly attrs?: Readonly<Record<string, string>>;
readonly require?: ContractRequirement;
readonly dischargedByState?: readonly string[];
}

type NoExtraKeys<Value, Allowed> = {
readonly [K in Exclude<keyof Value, keyof Allowed>]: never;
};

export type ExactContractRule<Rule, VMap> = Rule &
NoExtraKeys<Rule, ContractRule> &
(Rule extends { readonly require: infer Requirement }
? { readonly require: NoExtraKeys<Requirement, ContractRequirement> }
: unknown) &
(Rule extends { readonly when: infer When }
? { readonly when: NoExtraKeys<When, VMap> }
: unknown);

export type VariantOptionMap<V> = {
[K in keyof StripIndex<V>]: StripIndex<V>[K] extends {
variants: infer Options;
}
? VariantKeyOf<keyof Options>
: never;
};

export type ContractValues<T> = T extends readonly (infer Item extends string)[]
? Item
: T extends string
? T
: never;

export type ContractTagMatches<BoundTag extends string, WhenTag> = [
WhenTag,
] extends [undefined]
? true
: string extends BoundTag
? true
: [Extract<BoundTag, ContractValues<WhenTag>>] extends [never]
? false
: true;
80 changes: 13 additions & 67 deletions packages/effect-ui/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ import type {
CreateViewTransitionsFactory,
ClassResolver,
CompoundEntry,
ContractRequirement,
ContractRule,
ContractRuleEntry,
CSSPropMap,
CSSProps,
CustomPropConfig,
Expand All @@ -32,10 +35,14 @@ import type {
VariantKeyOf,
} from '@animus-ui/core';
import type {
ContractTagMatches,
ContractValues,
ExactContractRule,
StylingNames,
SystemPicks,
UnadmittedName,
UnadmittedStates,
VariantOptionMap,
} from '@animus-ui/core/binding';
import type { ClassResolverConfig } from '@animus-ui/core/runtime';

Expand Down Expand Up @@ -106,14 +113,6 @@ export type RequiredVariantKeys<V> = Extract<
string
>;

export type VariantOptionMap<V> = {
[K in keyof StripIndex<V>]: StripIndex<V>[K] extends {
variants: infer Options;
}
? VariantKeyOf<keyof Options>
: never;
};

type InitialVariantState<V> = {
[K in keyof StripIndex<V>]: DefaultVariantValue<StripIndex<V>[K]>;
};
Expand Down Expand Up @@ -144,71 +143,14 @@ type CustomValueMap<CP extends Record<string, SystemProp>> = {
>;
};

export interface ContractRequirement {
readonly attrs?: readonly string[];
readonly anyAttr?: readonly string[];
}

export interface ContractRule<
VMap = Readonly<Record<string, string>>,
StateKeys extends string = string,
> {
readonly when?: {
readonly [K in keyof VMap & string]?: VMap[K] | readonly VMap[K][];
};
readonly whenTag?: string | readonly string[];
readonly attrs?: Readonly<Record<string, string>>;
readonly require?: ContractRequirement;
readonly dischargedByState?: readonly StateKeys[];
}

type NoExtraKeys<Value, Allowed> = {
readonly [K in Exclude<keyof Value, keyof Allowed>]: never;
};

type ExactContractRule<Rule, VMap> = Rule &
NoExtraKeys<Rule, ContractRule> &
(Rule extends { readonly require: infer Requirement }
? { readonly require: NoExtraKeys<Requirement, ContractRequirement> }
: unknown) &
(Rule extends { readonly when: infer When }
? { readonly when: NoExtraKeys<When, VMap> }
: unknown);

export interface ContractRuleEntry {
readonly when?: Readonly<
Record<string, string | readonly string[] | undefined>
>;
readonly whenTag?: string | readonly string[];
readonly attrs?: Readonly<Record<string, string>>;
readonly require?: ContractRequirement;
readonly dischargedByState?: readonly string[];
}

interface ObligationUnit {
readonly attrs: string;
readonly states: string;
}

type ToUnion<T> = T extends readonly (infer Item extends string)[]
? Item
: T extends string
? T
: never;

type TagMatches<BoundTag extends string, WhenTag> = [WhenTag] extends [
undefined,
]
? true
: string extends BoundTag
? true
: [Extract<BoundTag, ToUnion<WhenTag>>] extends [never]
? false
: true;

type WhenEntriesMatch<CurrentV, When> = {
[K in keyof When & string]: K extends keyof CurrentV
? [Extract<CurrentV[K], ToUnion<When[K]>>] extends [never]
? [Extract<CurrentV[K], ContractValues<When[K]>>] extends [never]
? false
: true
: false;
Expand Down Expand Up @@ -256,7 +198,7 @@ type ActiveObligations<
? never
: C[number] extends infer Rule
? Rule extends ContractRuleEntry
? TagMatches<BoundTag, RuleWhenTag<Rule>> extends true
? ContractTagMatches<BoundTag, RuleWhenTag<Rule>> extends true
? VariantMatches<CurrentV, RuleWhen<Rule>> extends true
? RuleObligations<Rule>
: never
Expand Down Expand Up @@ -1457,6 +1399,10 @@ export interface EffectUiSystemBuilder<
export type {
ClassResolverConfig,
CompoundEntry,
ContractRequirement,
ContractRule,
ContractRuleEntry,
ResponsiveProp,
ThemedCSSPropMap,
VariantOptionMap,
};
Loading
Loading