@metacensus/library-research 0.13.0 → 0.15.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.
Files changed (46) hide show
  1. package/README.md +43 -11
  2. package/dist/commands/add.js +29 -12
  3. package/dist/commands/check.js +1 -1
  4. package/dist/commands/dev.js +24 -13
  5. package/dist/commands/reshape.d.ts +2 -0
  6. package/dist/commands/reshape.js +21 -0
  7. package/dist/context.d.ts +3 -1
  8. package/dist/context.js +2 -0
  9. package/dist/corpus.d.ts +432 -0
  10. package/dist/corpus.js +348 -0
  11. package/dist/data.d.ts +16 -12
  12. package/dist/data.js +38 -26
  13. package/dist/datasets.d.ts +8 -0
  14. package/dist/{roles.js → datasets.js} +35 -29
  15. package/dist/dev/host.d.ts +7 -1
  16. package/dist/dev/host.js +15 -13
  17. package/dist/host.d.ts +3 -1
  18. package/dist/host.js +6 -2
  19. package/dist/index.d.ts +3 -2
  20. package/dist/index.js +2 -1
  21. package/dist/mount.d.ts +7 -3
  22. package/dist/mount.js +7 -7
  23. package/dist/papers.js +3 -2
  24. package/dist/playwright.d.ts +1 -1
  25. package/dist/playwright.js +24 -6
  26. package/dist/project-id.d.ts +4 -0
  27. package/dist/project-id.js +7 -0
  28. package/dist/react.d.ts +18 -18
  29. package/dist/react.js +60 -37
  30. package/dist/reader.d.ts +18 -4
  31. package/dist/reader.js +25 -2
  32. package/dist/schema.d.ts +10 -35
  33. package/dist/schema.js +57 -34
  34. package/dist/testing.d.ts +11 -6
  35. package/dist/testing.js +12 -10
  36. package/dist/types.d.ts +62 -13
  37. package/dist/vite-config.js +2 -12
  38. package/dist/vite.d.ts +10 -2
  39. package/dist/vite.js +71 -19
  40. package/dist/zod.d.ts +2 -0
  41. package/dist/zod.js +4 -0
  42. package/package.json +14 -14
  43. package/schema/corpus.schema.json +3949 -29
  44. package/schema/project-id.schema.json +6 -0
  45. package/schema/research.schema.json +33 -7
  46. package/dist/roles.d.ts +0 -7
package/dist/schema.js CHANGED
@@ -1,43 +1,66 @@
1
- import { z } from 'zod';
2
- z.config({ jitless: true });
3
- export const kinds = {
4
- pdf: 'application/pdf',
5
- doc: 'application/msword',
6
- docx: 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
7
- xls: 'application/vnd.ms-excel',
8
- xlsx: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
9
- zip: 'application/zip',
10
- gif: 'image/gif',
11
- jpg: 'image/jpeg',
12
- tif: 'image/tiff',
13
- txt: 'text/plain',
14
- html: 'text/plain',
15
- xml: 'text/plain',
1
+ import { projectIdPattern } from './project-id.js';
2
+ import { z } from './zod.js';
3
+ export { Corpus, kinds } from './corpus.js';
4
+ const dataset = z.string().regex(/^(?!corpus$)[a-z][A-Za-z0-9]*$/);
5
+ /** A project's id, matching `projectIdPattern`. */
6
+ export const ProjectId = z
7
+ .string()
8
+ .regex(projectIdPattern)
9
+ .describe('A project id: lower-case letters, digits and hyphens, not starting with a hyphen');
10
+ const role = z.string().regex(/^[a-z][a-z0-9-]*$/);
11
+ const page = z.string().regex(/^[a-z0-9][a-z0-9-]*$/);
12
+ // Relative and without `..`, then `*`s only as `stars` says, and no other glob character.
13
+ const other = String.raw `[^*?[\]{}()!]*`;
14
+ const glob = (stars, rule) => {
15
+ const grammar = `a glob that is relative, has no .., ${rule}, and has none of ?[]{}()!`;
16
+ return z
17
+ .string()
18
+ .regex(new RegExp(`^(?!/)(?!.*\\.\\.)(?=.)${stars}$`), `must be ${grammar}`)
19
+ .describe(grammar);
16
20
  };
17
- const role = z.string().regex(/^(?!corpus$)[a-z][A-Za-z0-9]*$/);
18
- const glob = z.string().regex(/^(?!\/)(?!.*\.\.).+$/);
21
+ const dataGlob = glob(`${other}(?:\\*${other})?`, 'has at most one *');
22
+ const privateGlob = glob(`${other}\\*${other}`, 'has exactly one *');
19
23
  export const Research = z
20
24
  .strictObject({
21
25
  title: z.string().min(1),
22
- data: z.record(role, glob),
23
- private: z.record(role, glob).optional(),
24
- /** Each reader's private pages in `dev` and `testHost`; production's people.json holds the real mapping. */
26
+ data: z.record(dataset, dataGlob),
27
+ private: z.record(dataset, privateGlob).optional(),
28
+ /** The roles a person of the project holds one of. */
29
+ roles: z
30
+ .array(role)
31
+ .refine((roles) => new Set(roles).size === roles.length, 'roles repeat')
32
+ .meta({ uniqueItems: true })
33
+ .optional(),
34
+ /** The people `dev` and `testHost` serve, by username; production's people.json holds the real ones. */
25
35
  people: z
26
- .record(z.string(), z.array(z.string().regex(/^[a-z0-9][a-z0-9-]*$/)))
36
+ .record(z.string(), z.strictObject({
37
+ name: z.string().min(1),
38
+ role: z.string().optional(),
39
+ pages: z.array(page).optional(),
40
+ }))
27
41
  .optional(),
28
42
  })
29
- .superRefine(({ data, private: held = {} }, ctx) => {
30
- for (const [name, pattern] of Object.entries(held)) {
31
- const issue = (message) => ctx.addIssue({ code: 'custom', path: ['private', name], message });
32
- if (Object.hasOwn(data, name))
33
- issue(`role "${name}" is in data and private`);
34
- if (pattern.split('*').length !== 2 || /[?[\]{}()!]/.test(pattern))
35
- issue(`role "${name}": glob "${pattern}" must hold exactly one * and no other glob character`);
43
+ .superRefine(({ data, private: held = {}, roles, people = {} }, ctx) => {
44
+ for (const [username, person] of Object.entries(people)) {
45
+ const issue = (message) => ctx.addIssue({
46
+ code: 'custom',
47
+ path: ['people', username, 'role'],
48
+ message: `${username} ${message}`,
49
+ });
50
+ if (!roles) {
51
+ if (person.role !== undefined)
52
+ issue('has a role, and the project declares no roles');
53
+ }
54
+ else if (person.role === undefined)
55
+ issue('has no role, and the project declares roles');
56
+ else if (!roles.includes(person.role))
57
+ issue(`has role "${person.role}", which is not in roles`);
36
58
  }
59
+ for (const name of Object.keys(held))
60
+ if (Object.hasOwn(data, name))
61
+ ctx.addIssue({
62
+ code: 'custom',
63
+ path: ['private', name],
64
+ message: `dataset "${name}" is in data and private`,
65
+ });
37
66
  });
38
- export const Corpus = z.record(z.string().regex(/^[0-9a-f]{64}$/), z.strictObject({
39
- kind: z.enum(Object.keys(kinds)),
40
- title: z.string().optional(),
41
- citation: z.string().optional(),
42
- open: z.literal(true).optional(),
43
- }));
package/dist/testing.d.ts CHANGED
@@ -1,21 +1,26 @@
1
1
  import type { ReactElement } from 'react';
2
2
  import { type People } from './reader.js';
3
3
  import type { AnyProject } from './mount.js';
4
+ export { membersOf, readerOf, type People } from './reader.js';
4
5
  /** What `testHost` is given besides the project; every field is optional. */
5
6
  export interface TestHostOptions {
6
- /** Each data role's JSON value, parsed by the project's own schema. */
7
+ /** Each dataset's JSON value, parsed by the project's own schema. */
7
8
  data?: Record<string, unknown>;
8
- /** Each private role's pages, `{ role: { page: JSON } }`; the reader's page is the one named as the reader. */
9
+ /** Each private dataset's pages, `{ dataset: { page: JSON } }`; the reader sees those `people` gives them. */
9
10
  private?: Record<string, Record<string, unknown>>;
10
11
  /** Each document the project starts with, by id; `writer` defaults to the reader. */
11
12
  documents?: Record<string, {
12
13
  body: unknown;
13
14
  writer?: string;
14
15
  }>;
15
- /** Each reader's page keys, as research.json's `people`; a reader it omits holds the page named as them. */
16
+ /** The project's people, as research.json's `people`: each is a member, and `reader` holds their `pages`. */
16
17
  people?: People;
17
- /** The reader's username. */
18
+ /** The project's roles, as research.json's `roles`; with them, `reader` must be in `people`. */
19
+ roles?: string[];
20
+ /** The reader's username, and the writer of every save: `testHost` holds this one identity. */
18
21
  reader?: string;
22
+ /** False to view the project as `reader` while signed in as another; saves are still written as `reader`. */
23
+ self?: boolean;
19
24
  /** The path below the project, with search and hash. */
20
25
  url?: string;
21
26
  /** Called as `Host.sessionLost` is. */
@@ -26,8 +31,8 @@ export interface TestHostOptions {
26
31
  * path it names. Render `element` with any DOM renderer; `router` says where
27
32
  * the project navigated, and `documents()` what it saved, sorted by id.
28
33
  */
29
- export declare function testHost(project: AnyProject, { data, documents, private: held, people, reader, url, sessionLost, }?: TestHostOptions): {
30
- element: ReactElement<any, string | import("react").JSXElementConstructor<any>>;
34
+ export declare function testHost(project: AnyProject, { data, documents, private: held, people, roles, reader, self, url, sessionLost, }?: TestHostOptions): {
35
+ element: ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
31
36
  router: import("@tanstack/router-core").RouterCore<import("@tanstack/router-core").Route<import("@tanstack/react-router").Register, any, "/", "/", string, "__root__", undefined, {}, {}, import("@tanstack/react-router").AnyContext, import("@tanstack/react-router").AnyContext, {}, undefined, readonly [import("@tanstack/react-router").AnyRoute], unknown, unknown, unknown, undefined>, "preserve", false, import("@tanstack/history").RouterHistory, Record<string, any>>;
32
37
  documents: () => import("./types.js").Doc<unknown>[];
33
38
  };
package/dist/testing.js CHANGED
@@ -3,29 +3,31 @@ import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
3
3
  import { createMemoryHistory, RouterProvider } from '@tanstack/react-router';
4
4
  import { FetchContext } from './context.js';
5
5
  import { documentStore } from './document-store.js';
6
- import { pagesOf } from './reader.js';
6
+ import { membersOf, pagesOf, readerOf } from './reader.js';
7
7
  import { projectRouter } from './router.js';
8
+ export { membersOf, readerOf } from './reader.js';
8
9
  const origin = 'http://test.invalid';
9
10
  /**
10
11
  * A project rendered through the frame and the mount a real host uses, at the
11
12
  * path it names. Render `element` with any DOM renderer; `router` says where
12
13
  * the project navigated, and `documents()` what it saved, sorted by id.
13
14
  */
14
- export function testHost(project, { data = {}, documents = {}, private: held = {}, people, reader = 'test', url = '/', sessionLost = () => { }, } = {}) {
15
+ export function testHost(project, { data = {}, documents = {}, private: held = {}, people, roles, reader = 'test', self = true, url = '/', sessionLost = () => { }, } = {}) {
15
16
  const store = documentStore(documents, reader);
16
17
  const memory = (input, init) => store.handle(new Request(new URL(input instanceof Request ? input.url : input, origin), init), reader);
17
18
  const host = {
18
- reader: { username: reader },
19
- data(role) {
20
- if (!Object.hasOwn(data, role) || data[role] === undefined)
21
- throw new Error(`testHost: no data for role "${role}"`);
22
- return `data:application/json,${encodeURIComponent(JSON.stringify(data[role]))}`;
19
+ reader: readerOf({ people, roles }, reader, self),
20
+ members: membersOf(people),
21
+ data(dataset) {
22
+ if (!Object.hasOwn(data, dataset) || data[dataset] === undefined)
23
+ throw new Error(`testHost: no data for dataset "${dataset}"`);
24
+ return `data:application/json,${encodeURIComponent(JSON.stringify(data[dataset]))}`;
23
25
  },
24
- private: (role) => Object.fromEntries(pagesOf(people, reader)
25
- .filter((page) => Object.hasOwn(held[role] ?? {}, page))
26
+ private: (dataset) => Object.fromEntries(pagesOf(people, reader)
27
+ .filter((page) => Object.hasOwn(held[dataset] ?? {}, page))
26
28
  .map((page) => [
27
29
  page,
28
- `data:application/json,${encodeURIComponent(JSON.stringify(held[role][page]))}`,
30
+ `data:application/json,${encodeURIComponent(JSON.stringify(held[dataset][page]))}`,
29
31
  ])),
30
32
  paper: (sha) => `/papers/${sha}`,
31
33
  document: (id) => `${origin}/documents/${id}`,
package/dist/types.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import type { z } from 'zod';
2
- import type { Corpus as CorpusSchema, kinds } from './schema.js';
2
+ import type * as corpus from './corpus.js';
3
3
  /**
4
4
  * What a host gives a project: `frame` provides it and `useHost` returns it.
5
5
  * The methods are called during render, so each must be cheap and return the
@@ -8,10 +8,12 @@ import type { Corpus as CorpusSchema, kinds } from './schema.js';
8
8
  export interface Host {
9
9
  /** The person the project is viewed as, who may differ from the person signed in. */
10
10
  reader: Reader;
11
- /** The URL of a data role's JSON, `role` being one the project declares; `useData` fetches it. */
12
- data(role: string): string;
13
- /** The viewed person's pages of a private role: page key to URL; empty when they hold none. */
14
- private(role: string): Record<string, string>;
11
+ /** Every person of the project; `useMembers` returns it. */
12
+ members: Member[];
13
+ /** The URL of a dataset's JSON, `dataset` being one the project declares; `useData` fetches it. */
14
+ data(dataset: string): string;
15
+ /** The viewed person's pages of a private dataset: page key to URL; empty when they hold none. */
16
+ private(dataset: string): Record<string, string>;
15
17
  /** The URL of the paper stored under `sha`, as the corpus names it. */
16
18
  paper(sha: string): string;
17
19
  /**
@@ -34,15 +36,62 @@ export interface Doc<T> {
34
36
  revision: number;
35
37
  body: T;
36
38
  }
37
- /** The person a project is viewed as. */
38
- export interface Reader {
39
+ /**
40
+ * What a project declares of itself by augmenting this module:
41
+ * `datasets`, the type of ui/datasets.ts's export, and `roles`, research.json's
42
+ * roles as a union; `load` checks that ui/datasets.ts's `roles` tuple equals
43
+ * research.json's.
44
+ *
45
+ * @example
46
+ * declare module '@metacensus/library-research' {
47
+ * interface Register {
48
+ * datasets: typeof datasets
49
+ * roles: (typeof roles)[number]
50
+ * }
51
+ * }
52
+ */
53
+ export interface Register {
54
+ }
55
+ /** What parses a dataset's JSON: a Zod schema is one. */
56
+ export interface Schema {
57
+ parse(json: unknown): unknown;
58
+ }
59
+ /** The schemas of a project: those of `Register`'s `datasets`, else any by name. */
60
+ export type Schemas = Register extends {
61
+ datasets: infer D;
62
+ } ? D : Record<string, Schema>;
63
+ /** What a dataset's schema parses its JSON to. */
64
+ export type Data<K extends keyof Schemas> = Schemas[K] extends {
65
+ parse(json: unknown): infer T;
66
+ } ? T : unknown;
67
+ /** A person of the project. */
68
+ export interface Member {
39
69
  /** The name the host signs them in as. */
40
70
  username: string;
71
+ /** The name a person reads. */
72
+ name: string;
73
+ /** One of research.json's `roles`: `Register`'s where it declares them; null only in a project that declares none. */
74
+ role: Register extends {
75
+ roles: infer R;
76
+ } ? R : string | null;
77
+ }
78
+ /** The person a project is viewed as; `useReader` returns them. */
79
+ export interface Reader extends Member {
80
+ /** False while the host views the project as another person than the one signed in. */
81
+ self: boolean;
41
82
  }
42
- /** A kind of record the schema allows, one of `kinds`' keys. */
43
- export type Kind = keyof typeof kinds;
44
- /** The parsed `corpus` role: every paper by sha. */
45
- export type Corpus = z.infer<typeof CorpusSchema>;
46
- /** One paper of the corpus. */
47
- export type Paper = Corpus[string];
83
+ /** A kind of file the schema allows, one of `kinds`' keys. */
84
+ export type Kind = keyof typeof corpus.kinds;
85
+ /** The parsed `corpus` dataset: every work by id. */
86
+ export type Corpus = z.infer<typeof corpus.Corpus>;
87
+ /** One work: its CSL-JSON, its editions, and the fields pending a person. */
88
+ export type Work = z.infer<typeof corpus.Work>;
89
+ /** One edition of a work, holding its files by sha. */
90
+ export type Edition = z.infer<typeof corpus.Edition>;
91
+ /** One held file of an edition. */
92
+ export type Paper = z.infer<typeof corpus.Paper>;
93
+ /** A work's CSL-JSON metadata. */
94
+ export type Csl = z.infer<typeof corpus.Csl>;
95
+ /** What waits on a person: a placeholder's `key`, or a pending CSL field. */
96
+ export type Judgment = ReturnType<typeof corpus.pending>[number];
48
97
  export type { AnyProject, Mount, Project, RouterOf } from './mount.js';
@@ -1,22 +1,12 @@
1
1
  import react from '@vitejs/plugin-react';
2
- import { createRequire } from 'node:module';
3
2
  import { join } from 'node:path';
4
- import tailwind from 'tailwindcss';
5
- import { research, tailwindContent } from './vite.js';
3
+ import { research, tailwind } from './vite.js';
6
4
  export function hostConfig(root) {
7
5
  const projects = { project: root };
8
- const preset = createRequire(import.meta.url)('@metacensus/library-ui/tailwind3');
9
6
  return {
10
7
  root: join(root, 'ui'),
11
8
  configFile: false,
12
- plugins: [react(), research({ projects })],
13
- css: {
14
- postcss: {
15
- plugins: [
16
- tailwind({ presets: [preset], content: tailwindContent(projects) }),
17
- ],
18
- },
19
- },
9
+ plugins: [react(), research({ projects }), tailwind({ projects })],
20
10
  // library-research's modules stay unbundled so the host and the project
21
11
  // share one copy; Vite reads no imports inside node_modules, so theirs are
22
12
  // listed.
package/dist/vite.d.ts CHANGED
@@ -11,5 +11,13 @@ import { type Plugin } from 'vite';
11
11
  export declare function research({ projects, }: {
12
12
  projects: Record<string, string>;
13
13
  }): Plugin[];
14
- /** The Tailwind `content` globs that scan each project's `ui/`, skipping its `node_modules`; spread into the host's config. */
15
- export declare function tailwindContent(projects: Record<string, string>): string[];
14
+ /**
15
+ * Tailwind 4 for a host, as a plugin because a project's path comes from the
16
+ * host's environment, which a stylesheet's literal `@source` cannot hold. A
17
+ * host stylesheet importing `tailwindcss` gains each project's `ui/` as a
18
+ * source; a project stylesheet gains `@reference`s to Tailwind and library-ui's
19
+ * theme, so its `@apply` needs no boilerplate.
20
+ */
21
+ export declare function tailwind({ projects, }: {
22
+ projects: Record<string, string>;
23
+ }): Plugin[];
package/dist/vite.js CHANGED
@@ -1,8 +1,11 @@
1
1
  import { existsSync, readdirSync, readFileSync, realpathSync, statSync, } from 'node:fs';
2
2
  import { basename, dirname, join, relative, resolve, sep } from 'node:path';
3
+ import { fileURLToPath } from 'node:url';
3
4
  import { satisfies } from 'semver';
4
5
  import { isCSSRequest, preprocessCSS, searchForWorkspaceRoot, } from 'vite';
6
+ import tailwindcss from '@tailwindcss/vite';
5
7
  import { project, read } from './data.js';
8
+ import { checkProjectId } from './project-id.js';
6
9
  const prefix = 'projects';
7
10
  const dataPath = new RegExp(`^${prefix}/([^/]+)/data/([^/]+)\\.json$`);
8
11
  const privatePath = new RegExp(`^${prefix}/([^/]+)/private/([^/]+)/([^/]+)\\.json$`);
@@ -66,6 +69,8 @@ export function research({ projects, }) {
66
69
  name: 'research',
67
70
  config(user) {
68
71
  const from = resolve(user.root ?? '');
72
+ for (const slug of Object.keys(projects))
73
+ checkProjectId(slug, 'project');
69
74
  dirs = Object.entries(projects).map(([slug, path]) => [
70
75
  slug,
71
76
  realpathSync(resolve(from, path)),
@@ -169,18 +174,18 @@ export function research({ projects, }) {
169
174
  enforce: 'post',
170
175
  buildStart() {
171
176
  for (const [slug, dir] of dirs) {
172
- const { roles, pages } = project(dir);
173
- for (const [role, json] of Object.entries(roles))
177
+ const { datasets, pages } = project(dir);
178
+ for (const [dataset, json] of Object.entries(datasets))
174
179
  this.emitFile({
175
180
  type: 'asset',
176
- fileName: `${prefix}/${slug}/data/${role}.json`,
181
+ fileName: `${prefix}/${slug}/data/${dataset}.json`,
177
182
  source: JSON.stringify(json()),
178
183
  });
179
- for (const [role, held] of Object.entries(pages))
184
+ for (const [dataset, held] of Object.entries(pages))
180
185
  for (const [page, file] of Object.entries(held()))
181
186
  this.emitFile({
182
187
  type: 'asset',
183
- fileName: `${prefix}/${slug}/private/${page}/${role}.json`,
188
+ fileName: `${prefix}/${slug}/private/${page}/${dataset}.json`,
184
189
  source: JSON.stringify(read(dir, file)),
185
190
  });
186
191
  }
@@ -266,39 +271,86 @@ export function research({ projects, }) {
266
271
  const local = path.startsWith(config.base)
267
272
  ? path.slice(config.base.length)
268
273
  : '';
269
- const [, slug, role = ''] = local.match(dataPath) ?? [];
270
- const [, pslug, page = '', prole = ''] = local.match(privatePath) ?? [];
274
+ const [, slug, dataset = ''] = local.match(dataPath) ?? [];
275
+ const [, pslug, page = '', pdataset = ''] = local.match(privatePath) ?? [];
271
276
  const dir = dirs.find(([s]) => s === (slug ?? pslug))?.[1];
272
277
  if (!dir)
273
278
  return next();
274
279
  if (pslug) {
275
280
  // Gates nothing: the host's dev server decides who loads which page.
276
281
  const { pages } = project(dir);
277
- const held = Object.hasOwn(pages, prole) ? pages[prole]() : {};
282
+ const held = Object.hasOwn(pages, pdataset)
283
+ ? pages[pdataset]()
284
+ : {};
278
285
  const file = Object.hasOwn(held, page) ? held[page] : undefined;
279
286
  if (!file) {
280
287
  res.statusCode = 404;
281
- return res.end(`${pslug} has no private role "${prole}" page "${page}"`);
288
+ return res.end(`${pslug} has no private dataset "${pdataset}" page "${page}"`);
282
289
  }
283
290
  res.setHeader('Content-Type', 'application/json');
284
291
  return res.end(JSON.stringify(read(dir, file)));
285
292
  }
286
- const { roles } = project(dir);
287
- if (!Object.hasOwn(roles, role)) {
293
+ const { datasets } = project(dir);
294
+ if (!Object.hasOwn(datasets, dataset)) {
288
295
  res.statusCode = 404;
289
- return res.end(`${slug} has no role "${role}"`);
296
+ return res.end(`${slug} has no dataset "${dataset}"`);
290
297
  }
291
298
  res.setHeader('Content-Type', 'application/json');
292
- res.end(JSON.stringify(roles[role]()));
299
+ res.end(JSON.stringify(datasets[dataset]()));
293
300
  });
294
301
  },
295
302
  },
296
303
  ];
297
304
  }
298
- /** The Tailwind `content` globs that scan each project's `ui/`, skipping its `node_modules`; spread into the host's config. */
299
- export function tailwindContent(projects) {
300
- return Object.values(projects).flatMap((path) => [
301
- `${path}/ui/**/*.{ts,tsx}`,
302
- `!${path}/ui/node_modules/**`,
303
- ]);
305
+ /**
306
+ * Tailwind 4 for a host, as a plugin because a project's path comes from the
307
+ * host's environment, which a stylesheet's literal `@source` cannot hold. A
308
+ * host stylesheet importing `tailwindcss` gains each project's `ui/` as a
309
+ * source; a project stylesheet gains `@reference`s to Tailwind and library-ui's
310
+ * theme, so its `@apply` needs no boilerplate.
311
+ */
312
+ export function tailwind({ projects, }) {
313
+ // tailwindcss resolves from library-research, so a project's stylesheet
314
+ // builds with the host's copy wherever the project sits.
315
+ const references = [
316
+ [
317
+ 'tailwindcss',
318
+ fileURLToPath(import.meta.resolve('tailwindcss/index.css')),
319
+ ],
320
+ ['@metacensus/library-ui/theme.css', '@metacensus/library-ui/theme.css'],
321
+ ];
322
+ let dirs = [];
323
+ return [
324
+ {
325
+ name: 'research:tailwind',
326
+ enforce: 'pre',
327
+ configResolved({ root }) {
328
+ dirs = Object.values(projects).map((path) => join(realpathSync(resolve(root, path)), 'ui'));
329
+ },
330
+ transform(code, id) {
331
+ if (!cssCode(id))
332
+ return;
333
+ const file = id.split('?')[0];
334
+ const uses = (target, rules = 'import|reference') => new RegExp(`@(?:${rules})\\s+(['"])${escape(target)}\\1`).test(code);
335
+ const project = dirs.find((dir) => inside(file, dir));
336
+ if (project) {
337
+ if (relative(project, file).split(sep).includes('node_modules'))
338
+ return;
339
+ const lines = references
340
+ .filter(([target]) => !uses(target))
341
+ .map(([, path]) => `@reference ${JSON.stringify(path)};\n`);
342
+ return lines.length
343
+ ? { code: lines.join('') + code, map: null }
344
+ : undefined;
345
+ }
346
+ if (uses('tailwindcss', 'import'))
347
+ return {
348
+ code: code +
349
+ dirs.map((dir) => `\n@source ${JSON.stringify(dir)};`).join(''),
350
+ map: null,
351
+ };
352
+ },
353
+ },
354
+ ...tailwindcss(),
355
+ ];
304
356
  }
package/dist/zod.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ import { z } from 'zod';
2
+ export { z };
package/dist/zod.js ADDED
@@ -0,0 +1,4 @@
1
+ import { z } from 'zod';
2
+ // Before any schema is built: zod picks JIT at construction, and the host's CSP forbids eval.
3
+ z.config({ jitless: true });
4
+ export { z };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@metacensus/library-research",
3
- "version": "0.13.0",
3
+ "version": "0.15.0",
4
4
  "license": "AGPL-3.0-only",
5
5
  "repository": {
6
6
  "type": "git",
@@ -26,9 +26,9 @@
26
26
  "types": "./dist/testing.d.ts",
27
27
  "default": "./dist/testing.js"
28
28
  },
29
- "./roles": {
30
- "types": "./dist/roles.d.ts",
31
- "default": "./dist/roles.js"
29
+ "./datasets": {
30
+ "types": "./dist/datasets.d.ts",
31
+ "default": "./dist/datasets.js"
32
32
  },
33
33
  "./csp.json": "./csp.json",
34
34
  "./schema": {
@@ -59,25 +59,26 @@
59
59
  "dependencies": {
60
60
  "@axe-core/playwright": "^4.14.0",
61
61
  "@playwright/test": "^1.65.1",
62
- "@types/react": "^18.3.31",
63
- "@types/react-dom": "^18.3.7",
62
+ "@tailwindcss/vite": "^4.3.5",
63
+ "@types/react": "^19.3.3",
64
+ "@types/react-dom": "^19.3.0",
64
65
  "@vitejs/plugin-react": "^6.3.0",
65
66
  "semver": "^7.8.6",
66
- "tailwindcss": "^3.4.19",
67
+ "tailwindcss": "^4.3.5",
67
68
  "typescript": "^6.0.3",
68
69
  "zod": "^4.6.7"
69
70
  },
70
71
  "peerDependencies": {
71
- "@metacensus/library-ui": ">=0.6.0 <1",
72
+ "@metacensus/library-ui": ">=0.22.0 <1",
72
73
  "@tanstack/react-query": "^5",
73
74
  "@tanstack/react-router": "^1",
74
- "react": "^18.3.1",
75
- "react-dom": "^18.3.1",
75
+ "react": "^19",
76
+ "react-dom": "^19",
76
77
  "vite": "~8.3.8"
77
78
  },
78
79
  "devDependencies": {
79
80
  "@eslint/js": "^9.39.5",
80
- "@metacensus/library-ui": "^0.12.0",
81
+ "@metacensus/library-ui": "^0.22.0",
81
82
  "@tanstack/react-query": "^5.108.0",
82
83
  "@tanstack/react-router": "^1.170.46",
83
84
  "@types/jsdom": "^30.0.0",
@@ -86,10 +87,9 @@
86
87
  "eslint": "^9.39.5",
87
88
  "eslint-plugin-react-hooks": "^7.1.1",
88
89
  "jsdom": "^31.0.1",
89
- "postcss": "^8.5.33",
90
90
  "prettier": "^3.10.1",
91
- "react": "^18.3.1",
92
- "react-dom": "^18.3.1",
91
+ "react": "^19.3.1",
92
+ "react-dom": "^19.3.1",
93
93
  "typescript-eslint": "^8.73.0",
94
94
  "vite": "~8.3.8"
95
95
  }