@cagov/ca-ds 1.0.0 → 1.2.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 (101) hide show
  1. package/README.md +43 -26
  2. package/THIRD-PARTY-LICENSES.txt +690 -0
  3. package/ca-ds.js +48390 -0
  4. package/package.json +5 -31
  5. package/bin/ca-ds.js +0 -5
  6. package/src/cli/add.js +0 -134
  7. package/src/cli/build.js +0 -15
  8. package/src/cli/diff.js +0 -39
  9. package/src/cli/eject.js +0 -112
  10. package/src/cli/exit.js +0 -22
  11. package/src/cli/format.js +0 -52
  12. package/src/cli/init.js +0 -148
  13. package/src/cli/install.js +0 -178
  14. package/src/cli/items.js +0 -10
  15. package/src/cli/login.js +0 -331
  16. package/src/cli/main.js +0 -108
  17. package/src/cli/new.js +0 -230
  18. package/src/cli/outdated.js +0 -74
  19. package/src/cli/pack.js +0 -75
  20. package/src/cli/preview.js +0 -31
  21. package/src/cli/publish.js +0 -295
  22. package/src/cli/pull.js +0 -208
  23. package/src/cli/remote.js +0 -52
  24. package/src/cli/remove.js +0 -69
  25. package/src/cli/update.js +0 -223
  26. package/src/cli/validate.js +0 -131
  27. package/src/lib/browser.js +0 -12
  28. package/src/lib/build.js +0 -249
  29. package/src/lib/bundle.js +0 -148
  30. package/src/lib/catalog.js +0 -44
  31. package/src/lib/checks.js +0 -31
  32. package/src/lib/collection.js +0 -65
  33. package/src/lib/emblem.js +0 -29
  34. package/src/lib/fixtures.js +0 -59
  35. package/src/lib/floor.js +0 -79
  36. package/src/lib/glyph.js +0 -148
  37. package/src/lib/image.js +0 -138
  38. package/src/lib/json-text.js +0 -213
  39. package/src/lib/keys.js +0 -322
  40. package/src/lib/links.js +0 -321
  41. package/src/lib/markdown.js +0 -408
  42. package/src/lib/merge.js +0 -93
  43. package/src/lib/pack.js +0 -30
  44. package/src/lib/page-schema.js +0 -368
  45. package/src/lib/page.js +0 -372
  46. package/src/lib/patch.js +0 -9
  47. package/src/lib/regions.js +0 -173
  48. package/src/lib/registry.js +0 -371
  49. package/src/lib/release.js +0 -119
  50. package/src/lib/repoints.js +0 -120
  51. package/src/lib/resolve.js +0 -32
  52. package/src/lib/schema.js +0 -28
  53. package/src/lib/serial.js +0 -4
  54. package/src/lib/serialize.js +0 -444
  55. package/src/lib/structured.js +0 -72
  56. package/src/lib/system.js +0 -13
  57. package/src/lib/targets.js +0 -85
  58. package/src/lib/terms.js +0 -11
  59. package/src/lib/token-view.js +0 -289
  60. package/src/lib/tokens.js +0 -247
  61. package/src/lib/version.js +0 -34
  62. package/src/preview/frame.js +0 -75
  63. package/src/preview/pages.js +0 -128
  64. package/src/preview/screenshots.js +0 -72
  65. package/src/preview/server.js +0 -378
  66. package/src/preview/shell.js +0 -153
  67. package/src/schema/a11y.schema.json +0 -56
  68. package/src/schema/collection.lock.schema.json +0 -58
  69. package/src/schema/collection.schema.json +0 -65
  70. package/src/schema/composition.schema.json +0 -98
  71. package/src/schema/contract.schema.json +0 -116
  72. package/src/schema/interface.schema.json +0 -257
  73. package/src/schema/item.schema.json +0 -362
  74. package/src/schema/release.schema.json +0 -39
  75. package/src/schema/system.schema.json +0 -75
  76. package/src/schema/variants.schema.json +0 -60
  77. package/src/validate/collection.js +0 -19
  78. package/src/validate/collisions.js +0 -124
  79. package/src/validate/context.js +0 -357
  80. package/src/validate/facts.js +0 -253
  81. package/src/validate/files.js +0 -103
  82. package/src/validate/findings.js +0 -19
  83. package/src/validate/glyphs.js +0 -126
  84. package/src/validate/html.js +0 -215
  85. package/src/validate/imports.js +0 -29
  86. package/src/validate/index.js +0 -75
  87. package/src/validate/item.js +0 -47
  88. package/src/validate/links.js +0 -113
  89. package/src/validate/manifest.js +0 -147
  90. package/src/validate/media.js +0 -65
  91. package/src/validate/page.js +0 -74
  92. package/src/validate/prefixes.js +0 -58
  93. package/src/validate/relations.js +0 -310
  94. package/src/validate/release.js +0 -109
  95. package/src/validate/skill.js +0 -122
  96. package/src/validate/structured.js +0 -335
  97. package/src/validate/tasc.js +0 -80
  98. package/src/validate/template.js +0 -129
  99. package/src/validate/tokens.js +0 -154
  100. package/src/validate/zip.js +0 -40
  101. /package/{src/preview/preview.css → preview.css} +0 -0
package/src/lib/links.js DELETED
@@ -1,321 +0,0 @@
1
- // The legacy pointer, a repo path in a code span, still renders for versions published before links.
2
-
3
- import MarkdownIt from 'markdown-it';
4
- import { roleOf, recordIds, proseStrings, SUFFIX, TOPICS } from './structured.js';
5
- import { parseTarget, decodeFragment } from './targets.js';
6
-
7
- const md = new MarkdownIt({ html: false, linkify: false, typographer: false });
8
-
9
- // The grammar sits in ./targets.js, which imports nothing, so an editor's bundle skips the parser.
10
- export { parseTarget };
11
-
12
- export function seeTarget(see) {
13
- const target = parseTarget(see);
14
- return target && target.file === null && target.fragment !== null ? target : null;
15
- }
16
-
17
- // The docs site's heading ids. A repeat takes -1, -2, and on.
18
- export const slug = (text) =>
19
- text
20
- .trim()
21
- .toLowerCase()
22
- .replace(/[^\p{L}\p{N}\s_-]/gu, '')
23
- .replace(/\s/g, '-');
24
-
25
- const part = (s) => s.toLowerCase().replace(/[^a-z0-9]+/g, '-').replace(/^-|-$/g, '');
26
-
27
- export const sectionAnchor = (role) => (role === 'contract' ? 'rules' : role);
28
-
29
- // The docs site gives each record its id by this.
30
- export function recordAnchor(role, id) {
31
- if (role === 'contract') return `rule-${id}`;
32
- if (role === 'variants') return `variant-${id}`;
33
- if (role === 'accessibility') return `accessibility-${id}`;
34
- if (role === 'composition') return `composition-${part(id)}`;
35
- if (id.startsWith('.')) return `class-${part(id)}`;
36
- if (id.startsWith('--')) return `property-${part(id)}`;
37
- const event = /^([a-z][a-z0-9-]*)@(.+)$/.exec(id);
38
- if (event) return `event-${event[1]}-${part(event[2])}`;
39
- const owned = /^([a-z][a-z0-9-]*)\[(.+)\]$/.exec(id);
40
- if (owned) return `attribute-${owned[1]}-${part(owned[2])}`;
41
- if (/^ca-[a-z0-9]+(-[a-z0-9]+)*$/.test(id)) return `element-${id}`;
42
- return `attribute-${part(id)}`;
43
- }
44
-
45
- const PREFIXES = [
46
- ['rule-', 'contract'],
47
- ['variant-', 'variants'],
48
- ['accessibility-', 'accessibility'],
49
- ['composition-', 'composition'],
50
- ['element-', 'interface'],
51
- ['class-', 'interface'],
52
- ['property-', 'interface'],
53
- ['attribute-', 'interface'],
54
- ['event-', 'interface'],
55
- ];
56
- export const anchorRole = (anchor) => PREFIXES.find(([prefix]) => anchor.startsWith(prefix))?.[1] ?? null;
57
-
58
- export const recordAnchors = (role, data) => new Set([...recordIds(role, data)].map((id) => recordAnchor(role, id)));
59
-
60
- // Blanks a YAML frontmatter block line for line, so the lines after it keep their numbers.
61
- function body(text) {
62
- const m = /^?---\r?\n[\s\S]*?\r?\n---(?:\r?\n|$)/.exec(text);
63
- return m ? m[0].replace(/[^\n]/g, '') + text.slice(m[0].length) : text;
64
- }
65
-
66
- const plain = (tokens) => tokens.map((t) => (t.type === 'text' || t.type === 'code_inline' ? t.content : t.type === 'softbreak' ? ' ' : t.children ? plain(t.children) : '')).join('');
67
-
68
- export function headings(markdown) {
69
- const tokens = md.parse(body(markdown), {});
70
- const seen = new Map();
71
- const out = [];
72
- tokens.forEach((token, i) => {
73
- if (token.type !== 'heading_open') return;
74
- const text = plain(tokens[i + 1].children ?? []);
75
- let id = slug(text);
76
- const n = seen.get(id) ?? 0;
77
- seen.set(id, n + 1);
78
- if (n > 0) id = `${id}-${n}`;
79
- out.push({ id, text, level: Number(token.tag.slice(1)), line: token.map ? token.map[0] + 1 : null });
80
- });
81
- return out;
82
- }
83
-
84
- export function anchorsOf({ doc = null, structured = {} } = {}) {
85
- const heads = new Map();
86
- if (typeof doc === 'string') for (const h of headings(doc)) if (!heads.has(h.id)) heads.set(h.id, h.line);
87
- const records = new Map();
88
- const sections = new Map();
89
- for (const [role, data] of Object.entries(structured)) {
90
- if (!data) continue;
91
- sections.set(sectionAnchor(role), role);
92
- let anchors;
93
- try {
94
- anchors = recordAnchors(role, data);
95
- } catch {
96
- continue;
97
- }
98
- for (const a of anchors) if (!records.has(a)) records.set(a, role);
99
- }
100
- return { headings: heads, records, sections };
101
- }
102
-
103
- const SECTION_TITLES = { rules: 'Rules', variants: 'Variants', interface: 'Interface', accessibility: 'Accessibility', composition: 'Composition' };
104
-
105
- export function anchorList({ doc = null, structured = {} } = {}) {
106
- const out = [];
107
- const seen = new Set();
108
- const add = (entry) => {
109
- if (seen.has(entry.fragment)) return;
110
- seen.add(entry.fragment);
111
- out.push(entry);
112
- };
113
- if (typeof doc === 'string') for (const h of headings(doc)) add({ fragment: h.id, kind: 'heading', label: h.text, role: null, level: h.level });
114
- for (const [role, data] of Object.entries(structured)) {
115
- if (!data) continue;
116
- const section = sectionAnchor(role);
117
- add({ fragment: section, kind: 'section', label: SECTION_TITLES[section] ?? section, role, level: null });
118
- let ids;
119
- try {
120
- ids = [...recordIds(role, data)];
121
- } catch {
122
- continue;
123
- }
124
- for (const id of ids) add({ fragment: recordAnchor(role, id), kind: 'record', label: role === 'accessibility' ? (TOPICS[id] ?? id) : id, role, level: null });
125
- }
126
- return out;
127
- }
128
-
129
- export const hasAnchor = (anchors, fragment) => anchors.headings.has(fragment) || anchors.records.has(fragment) || anchors.sections.has(fragment);
130
-
131
- // Headings whose id a record or section also takes, which leave a link to either ambiguous.
132
- export const anchorCollisions = (anchors) =>
133
- [...anchors.headings].filter(([id]) => anchors.records.has(id) || anchors.sections.has(id)).map(([id, line]) => ({ id, line, role: anchors.records.get(id) ?? anchors.sections.get(id) }));
134
-
135
- export function itemPage(manifest, read) {
136
- const files = new Set(['item.json', ...(manifest.files ?? []).map((f) => f.path)]);
137
- const json = (path) => {
138
- const text = read(path);
139
- if (text === null) return null;
140
- try {
141
- return JSON.parse(text);
142
- } catch {
143
- return null;
144
- }
145
- };
146
- const structured = {};
147
- for (const f of manifest.files ?? []) {
148
- if (Object.hasOwn(SUFFIX, f.role) && !f.path.includes('/') && !structured[f.role]) structured[f.role] = json(f.path);
149
- }
150
- const doc = typeof manifest.doc === 'string' ? read(manifest.doc) : null;
151
- const anchors = anchorsOf({ doc, structured });
152
- const empty = { headings: new Map(), records: new Map(), sections: new Map() };
153
- return {
154
- name: manifest.name,
155
- files,
156
- anchors,
157
- fileAnchors(path) {
158
- if (!files.has(path)) return null;
159
- if (path === manifest.doc) return anchors;
160
- if (path.endsWith('.md')) {
161
- const text = read(path);
162
- return text === null ? null : { ...empty, headings: new Map(headings(text).map((h) => [h.id, h.line])) };
163
- }
164
- const role = roleOf(path);
165
- if (!role) return null;
166
- const data = path.includes('/') ? json(path) : structured[role];
167
- return data ? anchorsOf({ structured: { [role]: data } }) : null;
168
- },
169
- };
170
- }
171
-
172
- const anchorKind = (anchors, fragment) => (anchors.headings.has(fragment) ? 'heading' : anchors.sections.has(fragment) ? 'section' : 'record');
173
-
174
- export function resolveTarget(target, pageOf) {
175
- const { name, file, fragment } = target;
176
- const page = pageOf(name);
177
- if (!page) return { missing: 'item', name, file };
178
- if (file !== null && !page.files.has(file)) return { missing: 'file', name, file };
179
- if (fragment === null) return { name, file, fragment, kind: file === null ? 'item' : 'file' };
180
- const anchors = file === null ? page.anchors : page.fileAnchors(file);
181
- if (!anchors || !hasAnchor(anchors, fragment)) return { missing: 'anchor', name, file };
182
- const kind = anchorKind(anchors, fragment);
183
- const role = kind === 'record' ? anchors.records.get(fragment) : kind === 'section' ? anchors.sections.get(fragment) : null;
184
- return { name, file, fragment, kind, ...(role ? { role } : {}) };
185
- }
186
-
187
- const PATH = /^(?!\/)[A-Za-z0-9_./-]*\/[A-Za-z0-9_./-]*$/;
188
- // A URL written without its scheme.
189
- const HOST = /^[a-z0-9-]+(\.[a-z0-9-]+)+\//i;
190
-
191
- export const isPointer = (token) => {
192
- const path = recordPointer(token)?.path ?? token;
193
- return PATH.test(path) && !HOST.test(path) && (/^\.\.?\//.test(path) || /\.[A-Za-z0-9]+$/.test(path) || path.endsWith('/'));
194
- };
195
-
196
- export function recordPointer(token) {
197
- const i = token.indexOf('#');
198
- if (i < 1 || i === token.length - 1) return null;
199
- const path = token.slice(0, i);
200
- const role = roleOf(path);
201
- return role ? { path, role, id: token.slice(i + 1) } : null;
202
- }
203
-
204
- // A path into the package, the service, or a build names no item, nor does a folder such as standard/guidance/.
205
- const intoItem = (token) => {
206
- const path = recordPointer(token)?.path ?? token;
207
- return isPointer(token) && (/^\.\.?\//.test(path) || (path.startsWith('standard/') && !path.endsWith('/')));
208
- };
209
-
210
- const ABSOLUTE = /^([a-z][a-z0-9+.-]*:|\/|#)/i;
211
-
212
- // A code span's pointer and the § *Title* after it count as one.
213
- function scan(children, line, out) {
214
- let at = line;
215
- const link = (href, text, image) => {
216
- if (!href) return;
217
- const target = parseTarget(href);
218
- if (target) out.push({ type: 'link', href, text, image, line: at, target });
219
- else if (href.startsWith('#') && href.length > 1) out.push({ type: 'link', href, text, image, line: at, self: decodeFragment(href.slice(1)) });
220
- else if (!ABSOLUTE.test(href)) out.push({ type: 'legacy', form: 'relative', token: href, line: at });
221
- };
222
- for (let i = 0; i < children.length; i++) {
223
- const t = children[i];
224
- if (t.type === 'softbreak' || t.type === 'hardbreak') at = at === null ? null : at + 1;
225
- else if (t.type === 'image') link(t.attrGet('src'), plain(t.children ?? []), true);
226
- else if (t.type === 'link_open') {
227
- const close = children.findIndex((c, k) => k > i && c.type === 'link_close');
228
- link(t.attrGet('href'), plain(children.slice(i + 1, close === -1 ? undefined : close)), false);
229
- } else if (t.type === 'code_inline' && intoItem(t.content)) out.push({ type: 'legacy', form: 'code', token: t.content, line: at });
230
- else if (t.type === 'em_open' && children[i - 1]?.type === 'text' && /§ $/.test(children[i - 1].content) && !(children[i - 2]?.type === 'code_inline' && intoItem(children[i - 2].content))) out.push({ type: 'legacy', form: 'section', token: null, line: at });
231
- }
232
- }
233
-
234
- export function linksOf(markdown) {
235
- const out = [];
236
- for (const token of md.parse(body(markdown), {})) {
237
- if (token.type === 'inline' && token.children) scan(token.children, token.map ? token.map[0] + 1 : null, out);
238
- }
239
- return out;
240
- }
241
-
242
- export function inlineLinksOf(text) {
243
- const out = [];
244
- for (const token of md.parseInline(text, {})) if (token.children) scan(token.children, null, out);
245
- return out.map((l) => ({ ...l, line: null }));
246
- }
247
-
248
- export const proseLinksOf = (role, data) => proseStrings(role, data).flatMap(inlineLinksOf);
249
-
250
- // CommonMark: the next backtick run of the same length closes a span, and an unclosed run stays literal.
251
- function codeSpans(text) {
252
- const out = [];
253
- let i = 0;
254
- while (i < text.length) {
255
- if (text[i] === '\\') {
256
- i += 2;
257
- continue;
258
- }
259
- if (text[i] !== '`') {
260
- i++;
261
- continue;
262
- }
263
- let n = 0;
264
- while (text[i + n] === '`') n++;
265
- const run = new RegExp(`(?<!\`)\`{${n}}(?!\`)`, 'g');
266
- run.lastIndex = i + n;
267
- const close = run.exec(text);
268
- if (!close) {
269
- i += n;
270
- continue;
271
- }
272
- out.push([i, close.index + n]);
273
- i = close.index + n;
274
- }
275
- return out;
276
- }
277
-
278
- const INLINE_DEST = /(\]\(\s*)(<?)([^\s()<>]+)(>?)/g;
279
- const DEFINITION = /^( {0,3}\[[^\]]+\]:[ \t]*)(<?)(\S+?)(>?)(?=\s|$)/gm;
280
-
281
- // replace answers the new destination, or null to keep it. Links inside code stay, since they're text.
282
- export function rewriteTargets(markdown, replace) {
283
- const lines = markdown.split('\n');
284
- const code = new Array(lines.length).fill(false);
285
- for (const token of md.parse(body(markdown), {})) {
286
- if ((token.type === 'fence' || token.type === 'code_block') && token.map) for (let l = token.map[0]; l < token.map[1]; l++) code[l] = true;
287
- }
288
- const swap = (whole, dest, open, close, head) => {
289
- const target = parseTarget(dest);
290
- const href = target ? replace(target, dest) : null;
291
- return href === null ? whole : `${head}${open}${href}${close}`;
292
- };
293
- const prose = (chunk) => {
294
- const spans = codeSpans(chunk);
295
- let out = '';
296
- let at = 0;
297
- const outside = (text) =>
298
- text
299
- .replace(INLINE_DEST, (whole, head, open, dest, close) => swap(whole, dest, open, close, head))
300
- .replace(DEFINITION, (whole, head, open, dest, close) => swap(whole, dest, open, close, head));
301
- for (const [start, end] of spans) {
302
- out += outside(chunk.slice(at, start)) + chunk.slice(start, end);
303
- at = end;
304
- }
305
- return out + outside(chunk.slice(at));
306
- };
307
- const out = [];
308
- let run = [];
309
- const flush = () => {
310
- if (run.length) out.push(prose(run.join('\n')));
311
- run = [];
312
- };
313
- lines.forEach((line, l) => {
314
- if (code[l]) {
315
- flush();
316
- out.push(line);
317
- } else run.push(line);
318
- });
319
- flush();
320
- return out.join('\n');
321
- }