Skip to content

An open source design system that's fully customizable and agent ready

TypeScript

fix(core): a swizzled copy shares the animated-layout, code-language and snap-paging brands (#10576)

Cindy Zhang62bc7a2fe6c9
diff --git a/.changeset/core-shared-brands.md b/.changeset/core-shared-brands.md
new file mode 100644
index 0000000000..55ae7434ea
--- /dev/null
+++ b/.changeset/core-shared-brands.md
@@ -0,0 +1,7 @@
+---
+'@astryxdesign/core': patch
+---
+
+[fix] A swizzled copy and the package now agree on the animated-layout handle, code-language values and snap paging. A handle from `useAnimatedLayout` passed to a swizzled `AppShell`, `List`, `Table`, `TreeList`, `Collapsible` or `SideNav` no longer throws when the layout changes, and those copies type-check: each brand is read through a registered, versioned key at runtime, and the types carry one optional brand member that is never present. No API changes.
+
+@cixzhang
diff --git a/docs/specs/AST-105-animated-layout/spec.md b/docs/specs/AST-105-animated-layout/spec.md
index b2056314d8..2264e88c57 100644
--- a/docs/specs/AST-105-animated-layout/spec.md
+++ b/docs/specs/AST-105-animated-layout/spec.md
@@ -57,6 +57,9 @@ const animatedLayout = useAnimatedLayout({containerRef: scrollRef});
- **FR1 — One hook, one handle, one prop.** `useAnimatedLayout({containerRef})`
returns an opaque `animatedLayout` handle with no public methods or fields.
+ The handle's type carries one optional phantom brand member typed `never`,
+ so a package handle and a swizzled copy's handle match (`spec:AST-110` FR3);
+ it is never present at runtime and offers nothing to read or set.
An app passes it to a component whose size changes through that
component's `animatedLayout` prop, or a hook's `animatedLayout` option where
the component is a hook, and the component reports each change.
diff --git a/docs/specs/components/Carousel/Carousel.spec.md b/docs/specs/components/Carousel/Carousel.spec.md
index ebc25c7e09..a6fe6e2dea 100644
--- a/docs/specs/components/Carousel/Carousel.spec.md
+++ b/docs/specs/components/Carousel/Carousel.spec.md
@@ -110,7 +110,7 @@ Consumer migration instructions belong in consumer docs and release notes.
| FR2 | When the focused edge scroll button runs out, focus moves to the scroll area without scrolling it. This holds when the content no longer overflows and the scroll area is out of the tab order (`spec:AST-025` FR12): it still takes focus programmatically. Focus never lands on the page body or on a hidden button. | DEC-1; `spec:AST-085` FR4 | settled |
| FR3 | The handoff happens once per edge transition, and only while the edge button held focus. An edge reached by swipe, resize, or wheel while focus is elsewhere moves nothing. | `architecture:interaction-modality` INV8 | settled |
| FR4 | An edge scroll button that is available behaves as an ordinary Button. | `family:buttons` | settled |
-| FR5 | `hasSnap` takes `boolean \| SnapPaging`. Omitted or `false`: the scroll area does not snap. `true` (written `hasSnap`): native snap, FR6, exactly as released, with no gesture code. A `SnapPaging` value, made only by `useSnapPaging`: snap paging, FR7; the carousel snaps on native snap's per-item stops and the pager settles on those same stops. `true` never pages. A new `SnapPaging` value on a later render does not restart a settle or attach the gesture again. The third state is a known deviation from `architecture:public-component-api` INV3, which keeps a `has…` boolean to a true on/off (DEC-2). | DEC-2 | settled |
+| FR5 | `hasSnap` takes `boolean \| SnapPaging`. Omitted or `false`: the scroll area does not snap. `true` (written `hasSnap`): native snap, FR6, exactly as released, with no gesture code. A `SnapPaging` value, made only by `useSnapPaging`: snap paging, FR7; the carousel snaps on native snap's per-item stops and the pager settles on those same stops. `true` never pages. A new `SnapPaging` value on a later render does not restart a settle or attach the gesture again. The third state is a known deviation from `architecture:public-component-api` INV3, which keeps a `has…` boolean to a true on/off (DEC-2). A `SnapPaging` value is recognized through a registered key, and its type carries one optional phantom member typed `never`, so the package's value and a swizzled copy's match (`spec:AST-110` FR3); the member is never present at runtime and the value stays opaque. | DEC-2 | settled |
| FR6 | Native snap uses CSS scroll snap only: mandatory snap along the row on the scroll area, each direct child snapping at its start edge, and scroll padding matching the carousel's padding. Every item is a stop, also when several items show at once, and the platform's own momentum picks where a swipe rests. The current page reported is the page snapped into view when scrolling settles, and edge-button availability follows every scroll, momentum and programmatic included, and every resize. Native snap adds no gesture code. It does not depend on `::scroll-button()`, `::scroll-marker`, `:target-current`, scroll-state container queries, snap events, or `interactivity: inert`; one of these MAY be added under `@supports` only where it changes no behavior, name, role, or focus order. | DEC-2 | settled |
| FR7 | Snap paging uses native snap's stops (FR6): each direct child's start edge, measured from the inline start and mirrored in right-to-left layout, with the last stops clamped where the row ends so no empty space shows. A gap sits between stops and is never a stop. Under a finger, and on a trackpad swipe under every pointer (`spec:AST-094` FR43), a release picks its rest page by `spec:AST-094` FR3's paging rule: at most one page from the page the drag started on. The settle starts as `spec:AST-094` FR6's paging paragraph says. With the paging config, a flick moves one view by default: the release settles on the item start edge nearest one viewport on in the flick's direction, and the last page rests where the row ends; `{pages: 'item'}` moves one item per flick instead. Under right-to-left layout, pages run from the inline start. With one item per view both give the same stops. A mouse wheel keeps native snapping, and `hasSnap={true}` keeps native CSS snap under every pointer. An edge button steps about one view: the viewport width less half an item, landing on the nearest stop and moving at least one stop. Evidence gap: the one-item-per-flick feel is not yet measured against UIKit's group paging; measure before claiming parity. | DEC-2; `spec:AST-094` FR3, FR6, DEC-25 | settled |
| FR8 | Carousel's module imports no pager code: not the internal pager, its paging motion, or its gesture code. The `useSnapPaging` module imports that code statically, and Carousel calls only attach and detach on the `SnapPaging` value from an effect, and its moves of the row from Carousel's own scroll calls. The pager is tree-shaken by module boundary, with no lazy `import()` (`architecture:react-component-runtime` INV13), so a Carousel without `hasSnap={useSnapPaging()}` bundles no pager code. Importing the module does no DOM work. Under snap paging, the edge buttons, the edge fades and the handle's `canScrollPrev()`/`canScrollNext()` follow the held row, one state. | DEC-2; `architecture:react-component-runtime` INV13 | settled |
diff --git a/docs/specs/components/CodeBlock/CodeBlock.spec.md b/docs/specs/components/CodeBlock/CodeBlock.spec.md
index dbed22b3d5..632ba520d9 100644
--- a/docs/specs/components/CodeBlock/CodeBlock.spec.md
+++ b/docs/specs/components/CodeBlock/CodeBlock.spec.md
@@ -120,7 +120,7 @@ Consumer migration instructions belong in consumer docs and release notes.
| FR10 | `endContent` MUST render the caller's nodes beside Copy and before it in reading order: in the header when one exists, otherwise in the corner cluster (FR11); without Copy it keeps that place. It MUST sit outside the disclosure control, and pointer or keyboard activation inside it MUST NOT toggle collapse. CodeBlock MUST NOT name, restyle, or announce its content; the caller owns each control's name, state, and action. | proposal; the end-content slot of the Dialog and Drawer headers | verify |
| FR11 | With no header, the corner cluster MUST occupy its own inline-end column beside the code viewport, as wide as its content and never over the viewport, so that no line, at rest, scrolled, wrapped, or in either direction, is painted under a control; the cluster MUST be centred on the first line of code. A headerless block whose code is one line — counted after removing one trailing newline — therefore reads as one row: code, then the controls, with even space above and below; the single-line mode a caller gets by leaving out the title and passing `hasLanguageLabel={false}`. When the code gains lines, the block grows downward and the controls keep their place. A visible language label or a title keeps the header at every line count (FR3). The column paints from the `code-block` root, so no theme target is added. | the Code Body and Copy Button design relationships; proposal | verify |
| FR12 | Without the deprecated `tokenizer`, given a built-in identifier, CodeBlock MUST paint syntax for these built-in identifiers and their aliases: `typescript`/`ts`, `javascript`/`js`, `tsx`, `jsx`; `json`; `html`, `xml`, `svg`; `css`, `scss`, `less`; `python`/`py`; `bash`, `sh`, `zsh`, `shell`; `php`; `hack`; `yaml`/`yml`; `markdown`/`md`; `c`, `h`; `cpp`, `c++`, `cc`, `cxx`, `hpp`, `hh`; `sql`; `rust`/`rs`; `kotlin`, `kt`, `kts`; `swift`; `go`/`golang`. Each built-in paints the comment, string, number, and keyword tokens its language has from the syntax theme. Any other identifier renders as plain code with its label unless the deprecated `tokenizer` paints it; an identifier string never resolves to a language value. | proposal | verify |
-| FR13 | Each less common language MUST be its own module, one per subpath, each exporting one language value: `graphql` (`graphql`, `gql`), `java` (`java`), `thrift` (`thrift`), `objectiveC` (`objective-c`, `objc`, `m`, `mm`), `toml` (`toml`), `powershell` (`powershell`, `ps1`, `pwsh`), `ruby` (`ruby`, `rb`), `lua` (`lua`), and `dockerfile` (`dockerfile`, `docker`), at `@astryxdesign/core/CodeBlock/languages/<path>`, where `<path>` is the export's name in kebab case (`languages/graphql` exports `graphql`, `languages/objective-c` exports `objectiveC`). A language value is a `CodeLanguage` carrying everything needed to render that language: read-only `name` (the identifier its label shows, such as `graphql`: code text shown verbatim like a built-in identifier, never translated prose, so it needs no catalog entry), `identifiers`, `fileExtensions`, and `fileNames` (for example `graphql`, or `Dockerfile`), all required, and its grammar, which stays internal. `language` MUST accept a language value as well as an identifier string: given one, CodeBlock paints the code with that language, labels it with its `name`, and reflects its first identifier wherever it reflects the language, such as `data-language` on its theme targets (FR6), in the same render as a built-in would; a string selects only a built-in grammar (FR12). There is no provider, registry, or grouped export: each module is imported and passed on its own, and only modules a bundle imports reach it. A custom language is the same kind of value: `createCodeLanguage({name, identifiers, fileExtensions, fileNames, tokenize})`, exported from `@astryxdesign/core/CodeBlock`, makes one from a caller's `tokenize(code, language)` function returning `{type, start, end}` tokens, which runs synchronously; `fileExtensions` and `fileNames` default to none. It is passed and listed exactly like an Astryx module, and Astryx modules keep their grammar internal. In a `codeLanguages` list, a listed value takes precedence over a built-in with the same identifier, and a later entry over an earlier one. The released `tokenizer` prop is deprecated and still works exactly as released, taking precedence over the language's grammar; it is removed only at a minor release, and a codemod rewrites a block whose `language` is a static string literal other than `plaintext` to a custom language passed as `language`, whose first identifier is that string, and reports every other use it cannot rewrite. The exported `tokenize`, `tokenizeAsync`, and `tokenizeStreaming` MUST accept a language value wherever they accept a language identifier. A surface that sees only a fence's language word takes modules through its own prop: `Markdown`'s `codeLanguages` (`component:Markdown` FR30) and RichText's (`spec:AST-061`). Lab's `DiffViewer` takes a language value as its `language` the same way; without one it infers a file's language from the file's extension or name among the built-ins and the values in its own `codeLanguages`, and an unmatched file stays plain. It tokenizes each hunk's old and new side as continuous text with whichever grammar applies, and its line-number gutters and change marks are unaffected. Modules are opaque values: CodeBlock exposes no grammar format. The module is the portable form of a language (`spec:AST-082/FR3`): a platform CodeBlock takes the same kind of value for its language. | proposal | verify |
+| FR13 | Each less common language MUST be its own module, one per subpath, each exporting one language value: `graphql` (`graphql`, `gql`), `java` (`java`), `thrift` (`thrift`), `objectiveC` (`objective-c`, `objc`, `m`, `mm`), `toml` (`toml`), `powershell` (`powershell`, `ps1`, `pwsh`), `ruby` (`ruby`, `rb`), `lua` (`lua`), and `dockerfile` (`dockerfile`, `docker`), at `@astryxdesign/core/CodeBlock/languages/<path>`, where `<path>` is the export's name in kebab case (`languages/graphql` exports `graphql`, `languages/objective-c` exports `objectiveC`). A language value is a `CodeLanguage` carrying everything needed to render that language: read-only `name` (the identifier its label shows, such as `graphql`: code text shown verbatim like a built-in identifier, never translated prose, so it needs no catalog entry), `identifiers`, `fileExtensions`, and `fileNames` (for example `graphql`, or `Dockerfile`), all required, and its grammar, which stays internal. `language` MUST accept a language value as well as an identifier string: given one, CodeBlock paints the code with that language, labels it with its `name`, and reflects its first identifier wherever it reflects the language, such as `data-language` on its theme targets (FR6), in the same render as a built-in would; a string selects only a built-in grammar (FR12). There is no provider, registry, or grouped export: each module is imported and passed on its own, and only modules a bundle imports reach it. A custom language is the same kind of value: `createCodeLanguage({name, identifiers, fileExtensions, fileNames, tokenize})`, exported from `@astryxdesign/core/CodeBlock`, makes one from a caller's `tokenize(code, language)` function returning `{type, start, end}` tokens, which runs synchronously; `fileExtensions` and `fileNames` default to none. It is passed and listed exactly like an Astryx module, and Astryx modules keep their grammar internal. In a `codeLanguages` list, a listed value takes precedence over a built-in with the same identifier, and a later entry over an earlier one. The released `tokenizer` prop is deprecated and still works exactly as released, taking precedence over the language's grammar; it is removed only at a minor release, and a codemod rewrites a block whose `language` is a static string literal other than `plaintext` to a custom language passed as `language`, whose first identifier is that string, and reports every other use it cannot rewrite. The exported `tokenize`, `tokenizeAsync`, and `tokenizeStreaming` MUST accept a language value wherever they accept a language identifier. A surface that sees only a fence's language word takes modules through its own prop: `Markdown`'s `codeLanguages` (`component:Markdown` FR30) and RichText's (`spec:AST-061`). Lab's `DiffViewer` takes a language value as its `language` the same way; without one it infers a file's language from the file's extension or name among the built-ins and the values in its own `codeLanguages`, and an unmatched file stays plain. It tokenizes each hunk's old and new side as continuous text with whichever grammar applies, and its line-number gutters and change marks are unaffected. Modules are opaque values: CodeBlock exposes no grammar format. The module is the portable form of a language (`spec:AST-082/FR3`): a platform CodeBlock takes the same kind of value for its language. A language value's brand is read through a registered key, and its type carries one optional phantom member typed `never`, so the package's language values and a swizzled copy's match (`spec:AST-110` FR3); the member is never present at runtime and the value stays opaque. | proposal | verify |
| FR14 | Current state, not owner-reviewed. `startLineNumber` (default 1) MUST set the number of the first line in the source file. The gutter MUST show file coordinates (`startLineNumber + index`), so an excerpt reads with its real line numbers. A value below 1 MUST clamp to 1. `highlightLines` MUST use the same file coordinates, and an out-of-range entry MUST render no highlight. The offset MUST NOT change the displayed or copied source text (FR1). | released public type and JSDoc; shipped API | verify |
| FR15 | The copy control's glyph MUST resolve through the `code-block-copy` component icon slot, passing `{copied}`, which is true while the copied feedback (FR2) shows. With no theme entry, the glyph is `copy`, `check` while copied, and a cross while a failed write shows (FR2), when `{copied}` is false. When the slot resolves to no icon (a theme value of `null`, a slot function that returns `null`, or a request with `icon: null`), only the glyph is hidden: the control keeps its size, name, tooltip, and copy behavior, and shows no glyph at rest or while copied. A request `size` changes only the glyph, never the control. | proposal; `architecture:icon-resolution-and-component-slots/INV2,INV4–INV8` | verify |
diff --git a/internal/eslint-plugin-astryx/no-comment-provenance.baseline.json b/internal/eslint-plugin-astryx/no-comment-provenance.baseline.json
index 83c36ce4a7..1d1ecd3e7b 100644
--- a/internal/eslint-plugin-astryx/no-comment-provenance.baseline.json
+++ b/internal/eslint-plugin-astryx/no-comment-provenance.baseline.json
@@ -1884,7 +1884,6 @@
"DR3",
"DR3",
"DR3",
- "FR1",
"FR2",
"FR4",
"FR4",
@@ -1944,7 +1943,6 @@
"spec:AST-105",
"spec:AST-105",
"spec:AST-105",
- "spec:AST-105",
"spec:AST-105"
],
"packages/core/src/motion/animator.ts": [
diff --git a/packages/core/src/CodeBlock/grammar.ts b/packages/core/src/CodeBlock/grammar.ts
index 7f283f3f4e..9a659cabc1 100644
--- a/packages/core/src/CodeBlock/grammar.ts
+++ b/packages/core/src/CodeBlock/grammar.ts
@@ -13,6 +13,8 @@
* - /packages/core/src/CodeBlock/languages/
*/
+import {sharedKey} from '../utils/sharedRealm';
+
/** One grammar rule: text matching `regex` paints as `type`. */
export type GrammarPattern = {type: string; regex: RegExp};
@@ -23,7 +25,9 @@ export type Grammar = {
defaultType: string;
};
-const LANGUAGE = Symbol.for('astryx.codeLanguage');
+// A registered key, so a swizzled copy of this module accepts a package
+// language and the package accepts a copy's.
+const LANGUAGE = sharedKey('code-language', 1);
/** A flat token from a custom tokenize function: absolute offsets in `code`. */
export type CodeLanguageToken = {type: string; start: number; end: number};
@@ -49,7 +53,11 @@ export type CodeLanguage = {
readonly fileExtensions: ReadonlyArray<string>;
/** Whole file names that infer this language, such as `Dockerfile`. */
readonly fileNames: ReadonlyArray<string>;
- readonly [LANGUAGE]: true;
+ /**
+ * A brand that is never present, so the language types of the package and
+ * a swizzled copy match.
+ */
+ readonly '@astryxdesign/core/code-language/v1'?: never;
};
/** How a language value paints: Astryx grammar data or a custom function. */
@@ -58,6 +66,7 @@ export type CodeLanguagePainter =
| {kind: 'tokenize'; tokenize: CodeLanguageTokenize};
type InternalCodeLanguage = CodeLanguage & {
+ readonly [LANGUAGE]: true;
readonly painter: () => CodeLanguagePainter;
};
@@ -124,7 +133,7 @@ export function isCodeLanguage(value: unknown): value is CodeLanguage {
return (
typeof value === 'object' &&
value !== null &&
- (value as Partial<CodeLanguage>)[LANGUAGE] === true
+ (value as {readonly [LANGUAGE]?: unknown})[LANGUAGE] === true
);
}
diff --git a/packages/core/src/SnapPaging/snapPagingValue.ts b/packages/core/src/SnapPaging/snapPagingValue.ts
index 1e83df83c7..8e2abd490a 100644
--- a/packages/core/src/SnapPaging/snapPagingValue.ts
+++ b/packages/core/src/SnapPaging/snapPagingValue.ts
@@ -11,6 +11,7 @@
*/
import {isRtlElement} from '../hooks/isRtlElement';
+import {realmValue, sharedKey} from '../utils/sharedRealm';
/** Options of `useSnapPaging`. */
export interface SnapPagingOptions {
@@ -22,14 +23,16 @@ export interface SnapPagingOptions {
readonly pages?: 'view' | 'item';
}
-declare const snapPagingBrand: unique symbol;
-
/**
* Configured snap paging. Make it with `useSnapPaging`, and pass it to
* Carousel's `hasSnap`.
*/
export interface SnapPaging {
- readonly [snapPagingBrand]: true;
+ /**
+ * A brand that is never present, so the paging types of the package and a
+ * swizzled copy match.
+ */
+ readonly '@astryxdesign/core/snap-paging/v1'?: never;
}
/** The paging attached to one row. */
@@ -60,7 +63,11 @@ interface SnapPagingValue {
readonly attach: Attach;
}
-const values = new WeakSet<object>();
+// Registered, so a swizzled Carousel accepts the package's paging value.
+const values = realmValue(
+ sharedKey('snap-paging/values', 1),
+ () => new WeakSet<object>(),
+);
// Each attached row's paging, for Carousel's own scroll calls.
const attachments = new WeakMap<HTMLElement, SnapPagingAttachment>();
diff --git a/packages/core/src/motion/animatedLayout.ts b/packages/core/src/motion/animatedLayout.ts
index 56198c48a4..d402254e26 100644
--- a/packages/core/src/motion/animatedLayout.ts
+++ b/packages/core/src/motion/animatedLayout.ts
@@ -82,6 +82,7 @@
*/
import {LATE_START_MS} from './frameBlock';
+import {sharedKey} from '../utils/sharedRealm';
import {
inertCopy,
isCopyable,
@@ -722,15 +723,26 @@ export function glideOf(element: Element): Animation | null {
// Handles
// ---------------------------------------------------------------------------
-const AREA = Symbol('astryx.animatedLayout.area');
+// A registered key, so a swizzled copy of this module reads a package handle.
+const AREA = sharedKey('animated-layout/area', 1);
/**
- * The opaque handle `useAnimatedLayout` returns (`spec:AST-105` FR1): no
- * public members. A component that receives it reports its size changes to
- * the handle's container, the area the glide stays inside.
+ * The opaque handle `useAnimatedLayout` returns. A component that receives it
+ * reports its size changes to the handle's container, the area the glide
+ * stays inside.
*/
export interface AnimatedLayout {
- readonly [AREA]: () => Element | null;
+ /**
+ * A brand that is never present, so the handle types of the package and a
+ * swizzled copy match.
+ */
+ readonly '@astryxdesign/core/animated-layout/v1'?: never;
+}
+
+/** The container a handle reads, or null for a value that is not a handle. */
+function readArea(handle: AnimatedLayout): Element | null {
+ const read = (handle as {readonly [AREA]?: unknown})[AREA];
+ return typeof read === 'function' ? (read as () => Element | null)() : null;
}
/** A handle over `area` (the container element, read when a change runs). */
@@ -738,13 +750,11 @@ export function createAnimatedLayout(
area: () => Element | null,
): AnimatedLayout {
// Not enumerable and frozen: the handle shows no fields to a caller.
- return Object.freeze(
- Object.defineProperty({}, AREA, {value: area}),
- ) as AnimatedLayout;
+ return Object.freeze(Object.defineProperty({}, AREA, {value: area}));
}
function areaOf(handle: AnimatedLayout, element: Element): Element | null {
- const area = handle[AREA]();
+ const area = readArea(handle);
return area != null && area !== element && area.contains(element)
? area
: null;
@@ -2982,7 +2992,7 @@ export function playLayoutFrames(
handle: AnimatedLayout | null | undefined,
parts: LayoutSwapMotion['incoming'],
): () => void {
- const area = handle?.[AREA]() ?? null;
+ const area = handle == null ? null : readArea(handle);
const motion = area == null ? null : layoutMotion(area);
if (area == null || motion == null || motion.kind === 'instant') {
return () => {};
diff --git a/packages/core/src/utils/sharedBrands.test.ts b/packages/core/src/utils/sharedBrands.test.ts
new file mode 100644
index 0000000000..6eb028606a
--- /dev/null
+++ b/packages/core/src/utils/sharedBrands.test.ts
@@ -0,0 +1,86 @@
+// Copyright (c) Meta Platforms, Inc. and affiliates.
+
+/**
+ * A swizzled copy carries its own copy of a module that brands a value, such
+ * as the animated-layout handle. The package's values and the copy's must
+ * still be one type and one runtime protocol, so a package handle passed to
+ * a copied component works.
+ */
+
+import * as fs from 'node:fs';
+import * as os from 'node:os';
+import * as path from 'node:path';
+import {fileURLToPath} from 'node:url';
+import ts from 'typescript';
+import {describe, expect, it, vi} from 'vitest';
+
+const SRC = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..');
+
+describe('brands a swizzled copy shares with the package', () => {
+ it('a copy of the animated-layout module reads a package handle', async () => {
+ const pkg = await import('../motion/animatedLayout');
+ vi.resetModules();
+ const copy = await import('../motion/animatedLayout');
+ expect(copy).not.toBe(pkg);
+ const area = document.createElement('div');
+ const handle = pkg.createAnimatedLayout(() => area);
+ expect(() => copy.playLayoutFrames(handle, [])()).not.toThrow();
+ });
+
+ it('a copy of the snap-paging module accepts a package paging value', async () => {
+ const pkg = await import('../SnapPaging/snapPagingValue');
+ vi.resetModules();
+ const copy = await import('../SnapPaging/snapPagingValue');
+ expect(copy).not.toBe(pkg);
+ const value = pkg.makeSnapPaging(() => ({
+ detach: () => {},
+ move: () => {},
+ moveHeld: () => false,
+ }));
+ expect(copy.isSnapPaging(value)).toBe(true);
+ });
+
+ it('the package and a copy give the branded types one shape', () => {
+ // Two paths to Core's source that TypeScript reads as two modules each,
+ // as it reads a package module and the copy of it.
+ const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'astryx-brands-'));
+ try {
+ fs.symlinkSync(SRC, path.join(dir, 'pkg'), 'junction');
+ fs.symlinkSync(SRC, path.join(dir, 'copy'), 'junction');
+ const check = path.join(dir, 'check.ts');
+ const pairs = [
+ ['motion/animatedLayout', 'AnimatedLayout'],
+ ['CodeBlock/grammar', 'CodeLanguage'],
+ ['SnapPaging/snapPagingValue', 'SnapPaging'],
+ ];
+ fs.writeFileSync(
+ check,
+ pairs
+ .map(
+ ([file, name], i) =>
+ `import type {${name} as P${i}} from './pkg/${file}';\n` +
+ `import type {${name} as C${i}} from './copy/${file}';\n` +
+ `export const toCopy${i}: C${i} = null as unknown as P${i};\n` +
+ `export const toPackage${i}: P${i} = null as unknown as C${i};\n`,
+ )
+ .join(''),
+ );
+ const program = ts.createProgram([check], {
+ target: ts.ScriptTarget.ES2022,
+ module: ts.ModuleKind.ESNext,
+ moduleResolution: ts.ModuleResolutionKind.Bundler,
+ jsx: ts.JsxEmit.ReactJSX,
+ strict: true,
+ noEmit: true,
+ skipLibCheck: true,
+ preserveSymlinks: true,
+ });
+ const errors = program
+ .getSemanticDiagnostics(program.getSourceFile(check))
+ .map(d => ts.flattenDiagnosticMessageText(d.messageText, '\n'));
+ expect(errors).toEqual([]);
+ } finally {
+ fs.rmSync(dir, {recursive: true, force: true});
+ }
+ }, 120_000);
+});