@linked.archi/kernel 0.1.5 → 0.1.7

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 (35) hide show
  1. package/README.md +8 -0
  2. package/assets/archimate3/archimate3.2-metamodel.ttl +18 -1
  3. package/assets/archimate3/archimate3.2-principle-shapes.ttl +16 -22
  4. package/assets/archimate3/archimate3.2-questions.ttl +38 -38
  5. package/assets/archimate3/archimate3.2-viewpoint-shapes.ttl +1 -1
  6. package/assets/archimate4/archimate4-metamodel.ttl +18 -1
  7. package/assets/archimate4/archimate4-principle-shapes.ttl +38 -36
  8. package/assets/archimate4/archimate4-questions.ttl +38 -38
  9. package/assets/archimate4/archimate4-viewpoint-shapes.ttl +1 -1
  10. package/assets/catalog.ttl +776 -464
  11. package/assets/core/core-onto.ttl +12 -9
  12. package/assets/core/core-shapes.ttl +1 -1
  13. package/assets/core/core-vis-onto.ttl +99 -5
  14. package/assets/core/core-vis-shapes.ttl +275 -11
  15. package/package.json +5 -2
  16. package/src/model-manager/appearance.ts +131 -7
  17. package/src/model-manager/cascade.ts +5 -3
  18. package/src/model-manager/clipboard.ts +10 -2
  19. package/src/model-manager/concept-styles.ts +230 -0
  20. package/src/model-manager/interfaces.ts +19 -1
  21. package/src/model-manager/iri-conformance.ts +9 -2
  22. package/src/model-manager/placement-copy.ts +35 -8
  23. package/src/model-manager/questions.ts +6 -1
  24. package/src/model-manager/style-sets.ts +399 -0
  25. package/src/model-manager/style-values.ts +349 -0
  26. package/src/model-manager/view-manager.ts +74 -22
  27. package/src/model-manager/vocabulary.ts +10 -0
  28. package/src/rdf-engine/iri.ts +6 -3
  29. package/src/rdf-engine/native-load.ts +37 -0
  30. package/src/rdf-engine/observable-store.ts +98 -120
  31. package/src/rdf-engine/rdf-store.ts +14 -2
  32. package/src/rdf-engine/sparql-constraints.ts +15 -0
  33. package/src/rdf-engine/turtle-writer.ts +1 -0
  34. package/src/rdf-engine/validation-engine.ts +97 -32
  35. package/src/rdf-engine/validation-service.ts +3 -1
@@ -25,6 +25,15 @@
25
25
  * | `imagePosition` | `arch-vis:imagePosition` (0.7) | where: an `arch-vis:IconPlacement` — `TopLeft` … `BottomRight`, or `Fill` |
26
26
  * | `iconSymbol` | `arch-vis:iconSymbol` | a placement's own picture in place of its notation's glyph — with `IconCentric`, drawn as the figure; an `xsd:anyURI` as `image` |
27
27
  * | `useElementPicture` | `arch-vis:useElementPicture` (0.8) | `true`: its icon is its element's picture for the presentation shown — its badge in box-with-badge, its figure in icon mode; an `xsd:boolean` |
28
+ * | `basedOn` | `arch-vis:basedOn` (0.11) | the style its values are taken from where it sets none — a style set's named style, or its concept's own look — by IRI |
29
+ *
30
+ * ## Looks to share, and a concept's own (core-vis 0.11)
31
+ *
32
+ * `basedOn` is not a value of the look but where the values it does not set come from, so it is one of the
33
+ * {@link STYLE_KEYS} — what a style says — and none of the {@link APPEARANCE_KEYS}, the look's values. A
34
+ * diagram element is drawn with {@link drawnLook}: value by value, its style for the presentation shown, then
35
+ * the style that one is based on; its style for every presentation, then the style that one is based on; its
36
+ * concept's own look for the presentation shown — and, under all of them, its notation.
28
37
  *
29
38
  * ## A colour's alpha
30
39
  *
@@ -131,6 +140,12 @@ export interface Appearance {
131
140
  iconSymbol?: string;
132
141
  /** Its icon is its element's picture for the presentation shown — its badge, or its figure — followed, not copied (core-vis 0.8). */
133
142
  useElementPicture?: boolean;
143
+ /**
144
+ * The style it takes its values from where it sets none, followed as that one changes (core-vis 0.11): a style
145
+ * set's named style, or the look for every presentation of the concept it draws — by IRI. Not a value of the
146
+ * look: in {@link STYLE_KEYS}, not in {@link APPEARANCE_KEYS}.
147
+ */
148
+ basedOn?: string;
134
149
  }
135
150
 
136
151
  export type AppearanceKey = keyof Appearance;
@@ -138,7 +153,7 @@ export type AppearanceKey = keyof Appearance;
138
153
  /** Changes to an appearance: a value sets it, `null` takes it back to the default, absent leaves it. */
139
154
  export type AppearanceChanges = { [K in AppearanceKey]?: Appearance[K] | null };
140
155
 
141
- /** The keys, in the order the Appearance tab lists them. */
156
+ /** A look's values, in the order the Appearance tab lists them — not `basedOn`, which says where they come from. */
142
157
  export const APPEARANCE_KEYS: readonly AppearanceKey[] = [
143
158
  'fillColor',
144
159
  'gradient',
@@ -164,6 +179,9 @@ export const APPEARANCE_KEYS: readonly AppearanceKey[] = [
164
179
  'useElementPicture',
165
180
  ];
166
181
 
182
+ /** What a style says: its look's values, and the style it is based on (core-vis 0.11). */
183
+ export const STYLE_KEYS: readonly AppearanceKey[] = [...APPEARANCE_KEYS, 'basedOn'];
184
+
167
185
  const ENUMERATIONS = {
168
186
  borderStyle: { SolidLine: VIS + 'SolidLine', DashedLine: VIS + 'DashedLine', DottedLine: VIS + 'DottedLine' },
169
187
  textAlignment: { left: VIS + 'AlignLeft', center: VIS + 'AlignCenter', right: VIS + 'AlignRight' },
@@ -201,6 +219,7 @@ export const APPEARANCE_PREDICATES: Record<AppearanceKey, string> = {
201
219
  imagePosition: VIS + 'imagePosition',
202
220
  iconSymbol: VIS + 'iconSymbol',
203
221
  useElementPicture: VIS + 'useElementPicture',
222
+ basedOn: VIS + 'basedOn',
204
223
  };
205
224
 
206
225
  /** How a value is written: an enumeration's member (an IRI), an integer, a boolean, or a string. */
@@ -213,7 +232,7 @@ export function appearanceObject(
213
232
  const iri = (ENUMERATIONS[key] as Record<string, string>)[String(value)];
214
233
  return iri ? { iri } : undefined;
215
234
  }
216
- if (key === 'shapeType') {
235
+ if (key === 'shapeType' || key === 'basedOn') {
217
236
  const iri = String(value).trim();
218
237
  return /^[a-z][\w+.-]*:/i.test(iri) ? { iri } : undefined;
219
238
  }
@@ -240,7 +259,7 @@ export function appearanceValue<K extends AppearanceKey>(key: K, term: { termTyp
240
259
  const members = ENUMERATIONS[key] as Record<string, string>;
241
260
  return Object.keys(members).find((member) => members[member] === value) as Appearance[K] | undefined;
242
261
  }
243
- if (key === 'shapeType') return (term.termType === 'NamedNode' ? value : undefined) as Appearance[K] | undefined;
262
+ if (key === 'shapeType' || key === 'basedOn') return (term.termType === 'NamedNode' ? value : undefined) as Appearance[K] | undefined;
244
263
  if (key === 'lineWidth' || key === 'fontSize') {
245
264
  const n = Number(value);
246
265
  return (Number.isFinite(n) && n > 0 ? n : undefined) as Appearance[K] | undefined;
@@ -364,9 +383,9 @@ function round3(n: number): number {
364
383
  return Math.round(n * 1000) / 1000;
365
384
  }
366
385
 
367
- /** Whether two appearances say the same. */
386
+ /** Whether two appearances say the same — the style each is based on too. */
368
387
  export function sameAppearance(a: Appearance | undefined, b: Appearance | undefined): boolean {
369
- return APPEARANCE_KEYS.every((key) => (a?.[key] ?? undefined) === (b?.[key] ?? undefined));
388
+ return STYLE_KEYS.every((key) => (a?.[key] ?? undefined) === (b?.[key] ?? undefined));
370
389
  }
371
390
 
372
391
  /** The look a style — a notation's, a thing's own — says, from whatever of the keys it has. */
@@ -383,7 +402,112 @@ export function lookOf(style: object | undefined): Appearance {
383
402
  return look as Appearance;
384
403
  }
385
404
 
386
- /** An appearance with nothing set is none. */
405
+ /** An appearance with nothing set is none — one based on a style says something. */
387
406
  export function appearanceOrNone(appearance: Appearance): Appearance | undefined {
388
- return APPEARANCE_KEYS.some((key) => appearance[key] !== undefined) ? appearance : undefined;
407
+ return STYLE_KEYS.some((key) => appearance[key] !== undefined) ? appearance : undefined;
408
+ }
409
+
410
+ /** A look's values alone: what `appearance` sets of the {@link APPEARANCE_KEYS}, without the style it is based on. */
411
+ export function lookValues(appearance: Appearance | undefined): Appearance {
412
+ const values: Record<string, unknown> = {};
413
+ for (const key of APPEARANCE_KEYS) if (appearance?.[key] !== undefined) values[key] = appearance[key];
414
+ return values as Appearance;
415
+ }
416
+
417
+ /**
418
+ * What a style says once it is no longer based on another (core-vis 0.11's detaching): its own values, and the
419
+ * values of the style it was based on where it sets none — so it looks as it did — with no `basedOn`.
420
+ */
421
+ export function detachedLook(appearance: Appearance, base: Appearance | undefined): Appearance {
422
+ return { ...lookValues(base), ...lookValues(appearance) };
423
+ }
424
+
425
+ /** What a diagram element is drawn from, besides its notation: as a node's or a link's info gives it. */
426
+ export interface LookSources {
427
+ /** Its style for every presentation context. */
428
+ appearance?: Appearance;
429
+ /** Its style for each presentation context it has one for. */
430
+ contextAppearances?: Record<string, Appearance>;
431
+ /** The looks for every presentation context of the styles its styles are based on (`basedOn`), by their IRIs. */
432
+ basedOnLooks?: Record<string, Appearance>;
433
+ /**
434
+ * Their looks for each presentation context (core-vis 0.11), by the based-on style's IRI, then the context's: a
435
+ * named style's — the styles of its set based on it, each for a context — or its concept's own looks for each.
436
+ */
437
+ basedOnContextLooks?: Record<string, Record<string, Appearance>>;
438
+ }
439
+
440
+ /**
441
+ * What a style based on `base` takes from it, drawn for `context`: the base's look for that context over its look
442
+ * for every context — for no context, the latter alone. Empty for no base.
443
+ */
444
+ export function baseLook(sources: LookSources, base: string | undefined, context?: string): Appearance {
445
+ if (!base) return {};
446
+ return { ...lookValues(sources.basedOnLooks?.[base]), ...lookValues(context ? sources.basedOnContextLooks?.[base]?.[context] : undefined) };
447
+ }
448
+
449
+ /**
450
+ * The look a diagram element is drawn with for `context` — or for no presentation context — over its notation,
451
+ * which the caller draws under it (core-vis 0.11's order, `arch-vis:style`). Value by value, the first that
452
+ * says it:
453
+ *
454
+ * 1. its style for `context`; then the style that one is based on, its look for `context`, then for every context;
455
+ * 2. its style for every context; then the style that one is based on, the same way ({@link baseLook}).
456
+ *
457
+ * A named style, or its concept's own look, is drawn only where one of its styles is based on it. `undefined` when
458
+ * nothing sets a value. Never `basedOn`: what it names is read already.
459
+ */
460
+ export function drawnLook(sources: LookSources, context?: string): Appearance | undefined {
461
+ const own = sources.appearance;
462
+ const forContext = context ? sources.contextAppearances?.[context] : undefined;
463
+ // From the last to win to the first: each layer's values over those under it.
464
+ const layers = [baseLook(sources, own?.basedOn, context), own, baseLook(sources, forContext?.basedOn, context), forContext];
465
+ const look: Record<string, unknown> = {};
466
+ for (const layer of layers) Object.assign(look, lookValues(layer));
467
+ return appearanceOrNone(look as Appearance);
468
+ }
469
+
470
+ /**
471
+ * A diagram element's styles with the bases `detach` says go — given the base and the context the style is for, none
472
+ * for every context — written into them (meta's DD-47), so that it is drawn as before for every presentation context:
473
+ * a style based on one takes its values where it sets none — for a
474
+ * context, the base's look for that context first ({@link baseLook}) — and is based on nothing. The base of its
475
+ * style for every context gives its looks for each context to its style for that context, made where it has none,
476
+ * wherever nothing drawn before them there sets the value. What a paste into another model, which does not have the
477
+ * style, writes (`placement-copy.ts`), and what deleting a style writes in the store (`style-values.ts`'
478
+ * `detachAllChange`).
479
+ */
480
+ export function detachedLooks(
481
+ sources: LookSources,
482
+ detach: (base: string, context: string | undefined) => boolean,
483
+ ): { appearance?: Appearance; contextAppearances?: Record<string, Appearance> } {
484
+ const own = sources.appearance;
485
+ const goesEvery = own?.basedOn && detach(own.basedOn, undefined) ? own.basedOn : undefined;
486
+ const appearance = goesEvery ? appearanceOrNone(detachedLook(own!, baseLook(sources, goesEvery))) : own;
487
+ const ownValues = lookValues(own);
488
+ const contextIris = new Set([
489
+ ...Object.keys(sources.contextAppearances ?? {}),
490
+ ...(goesEvery ? Object.keys(sources.basedOnContextLooks?.[goesEvery] ?? {}) : []),
491
+ ]);
492
+ const contextAppearances: Record<string, Appearance> = {};
493
+ for (const context of [...contextIris].sort()) {
494
+ const style = sources.contextAppearances?.[context];
495
+ const goes = style?.basedOn && detach(style.basedOn, context) ? style.basedOn : undefined;
496
+ const look: Record<string, unknown> = goes ? { ...baseLook(sources, goes, context), ...lookValues(style) } : { ...style };
497
+ // What its style for every context took from its base for this context, where nothing before it says it.
498
+ if (goesEvery) {
499
+ const kept = goes ? {} : baseLook(sources, style?.basedOn, context);
500
+ const given = lookValues(sources.basedOnContextLooks?.[goesEvery]?.[context]);
501
+ for (const key of APPEARANCE_KEYS) {
502
+ if (given[key] === undefined || look[key] !== undefined || kept[key] !== undefined || ownValues[key] !== undefined) continue;
503
+ look[key] = given[key];
504
+ }
505
+ }
506
+ const result = appearanceOrNone(look as Appearance);
507
+ if (result) contextAppearances[context] = result;
508
+ }
509
+ return {
510
+ ...(appearance ? { appearance } : {}),
511
+ ...(Object.keys(contextAppearances).length > 0 ? { contextAppearances } : {}),
512
+ };
389
513
  }
@@ -33,6 +33,7 @@
33
33
  import type { NamedNode, Quad, Term } from '@rdfjs/types';
34
34
  import type { RdfStore } from '../rdf-engine/interfaces.js';
35
35
  import { NAMESPACES } from '../rdf-engine/namespaces.js';
36
+ import { conceptStyleQuads } from './concept-styles.js';
36
37
  import { CUSTOM_PROPERTY } from './custom-properties.js';
37
38
  import { IRI, T, dedupe, nn, relationshipClassAmong } from './vocabulary.js';
38
39
 
@@ -107,11 +108,12 @@ export function relationshipClassOf(store: RdfStore, relationshipIri: string): s
107
108
  /**
108
109
  * What goes with a diagram element or a concept that nothing else uses: a
109
110
  * node's or a link's own styles (`arch-vis:style`, each context's too) and the label expressions they
110
- * gives (core-vis 0.7), and a concept's SKOS-XL names and pictures (core 0.5.0)
111
- * — each only when no other subject points at it.
111
+ * gives (core-vis 0.7), a concept's SKOS-XL names and pictures (core 0.5.0) and its own looks (core-vis 0.11's
112
+ * `arch-vis:conceptStyle`) — each only when no other subject points at it.
112
113
  */
113
114
  function ownedQuads(store: RdfStore, subject: Term): Quad[] {
114
- const quads: Quad[] = [];
115
+ // Its own looks: its diagram elements, based on them, go with it too.
116
+ const quads: Quad[] = [...conceptStyleQuads(store, subject.value)];
115
117
  const alone = (predicate: NamedNode, object: Term) => store.getQuads(null, predicate, object as NamedNode).length <= 1;
116
118
  for (const style of store.getQuads(subject as NamedNode, T.visStyle)) {
117
119
  if (style.object.termType === 'Literal' || !alone(T.visStyle, style.object)) continue;
@@ -27,6 +27,8 @@ import { N3TtlSerializer } from '../rdf-engine/ttl-serializer.js';
27
27
  import { NAMESPACES } from '../rdf-engine/namespaces.js';
28
28
  import { OxigraphViewManager } from './view-manager.js';
29
29
  import { copyPlacements } from './placement-copy.js';
30
+ import { mayBaseOn } from './style-sets.js';
31
+ import { baseContextLookQuads } from './style-values.js';
30
32
  import { isFolder, membershipQuads } from './folders.js';
31
33
  import { AUTO_LAYOUT } from './grid.js';
32
34
  import { quadsOf, snapshotOf } from './version-history.js';
@@ -182,10 +184,11 @@ function conceptQuads(store: RdfStore, iri: string, modelIri: string): Quad[] {
182
184
  * named under the placement — `{node}-style`, `{link}-points-0`, `{link}-label` (DD-41, and as la-gram named
183
185
  * them before), or `{node}/style`, `{link}/points/0`, `{link}/label` — and through its style, its label
184
186
  * expressions, its moved name and its route's cells and points, which may be named otherwise (another
185
- * tool's, or shared).
187
+ * tool's, or shared). And the style its style is based on (core-vis 0.11) — a set's named style, its concept's
188
+ * saved look — whose values a paste writes in where it may not stay based on it; never the set itself.
186
189
  */
187
190
  function placementQuads(store: RdfStore, placementIri: string): Quad[] {
188
- const FOLLOWED = new Set([IRI.visStyle, IRI.labelExpression, IRI.visLabel, IRI.points, IRI.rdfFirst, IRI.rdfRest]);
191
+ const FOLLOWED = new Set([IRI.visStyle, IRI.labelExpression, IRI.visLabel, IRI.points, IRI.rdfFirst, IRI.rdfRest, IRI.basedOn]);
189
192
  const quads: Quad[] = [];
190
193
  const seen = new Set<string>();
191
194
  const queue: Term[] = [nn(placementIri)];
@@ -205,6 +208,8 @@ function placementQuads(store: RdfStore, placementIri: string): Quad[] {
205
208
  if (owned) queue.push(o);
206
209
  }
207
210
  }
211
+ // The based-on styles' looks for each presentation context, which a paste writes in with them (core-vis 0.11).
212
+ for (const q of quads.filter((quad) => quad.predicate.value === IRI.basedOn)) quads.push(...baseContextLookQuads(store, q.object));
208
213
  return quads;
209
214
  }
210
215
 
@@ -519,6 +524,9 @@ export function pasteFragment(deps: PasteDeps, fragment: ClipboardFragment, targ
519
524
  links: new Set(links.map((l) => l.linkIri)),
520
525
  concept: conceptIn,
521
526
  offset,
527
+ // Based on a style the target has and may be based on — a set it uses, the concept's own look — it stays
528
+ // so; otherwise the style's values are written in (core-vis 0.11; meta's DD-47).
529
+ keepsBase: (base, concept) => mayBaseOn(store, target.modelIri, concept, base),
522
530
  });
523
531
  result.nodes = [...placed.nodes.values()];
524
532
  result.links = [...placed.links.values()];
@@ -0,0 +1,230 @@
1
+ /**
2
+ * A model concept's own looks (core-vis 0.11's `arch-vis:conceptStyle`): an element's, a relationship's, a
3
+ * view's — as distinct from its type's notation and from a diagram element's own style. Given as its names and
4
+ * pictures for an audience are (`context-names.ts`, `element-pictures.ts`): at most one for every presentation
5
+ * context, and one for each (`arch:inPresentationContext` on the style) — together a style of its own, complete
6
+ * for each audience, as a named style and its looks for each context are (`style-sets.ts`).
7
+ *
8
+ * Its looks are kept for its diagram elements to take, never drawn by themselves: a diagram element whose style is
9
+ * based on its look for every context — its saved look (`arch-vis:basedOn`) — is drawn with them, for a context its
10
+ * look for that context first (`drawnLook`). So a system keeps a look of its own, and is drawn as its type is until
11
+ * one of its diagram elements is given it. Its look for every context is what is based on: made with its first look
12
+ * for a context, it stays, saying nothing of its own, while the concept has one.
13
+ *
14
+ * A concept's look is based on no other style and is in no style set (core-vis-shapes 0.7.0). la-gram names it after
15
+ * the concept — `{concept}/style`, `{concept}/style/{hash}` for a context (DD-41) — so that a merge can match it; one
16
+ * another tool wrote as a blank node is named so when it changes. A look for a context emptied or taken away goes,
17
+ * and what is based on the saved look follows; the look as a whole deleted leaves what it gave with the styles based
18
+ * on it (`deleteConceptLookChange`, `detachAllChange`).
19
+ */
20
+
21
+ import { DataFactory } from 'n3';
22
+ import type { NamedNode, Quad, Term } from '@rdfjs/types';
23
+ import type { RdfStore } from '../rdf-engine/interfaces.js';
24
+ import { isPartNamed, partIri } from '../rdf-engine/iri.js';
25
+ import { APPEARANCE_KEYS, APPEARANCE_PREDICATES, lookValues, type Appearance, type AppearanceChanges } from './appearance.js';
26
+ import { shortHash } from './short-hash.js';
27
+ import { appearanceTerm, detachAllChange, lookOfStyle, styleAppearance } from './style-values.js';
28
+ import { IRI, T, netChange, nn, triple } from './vocabulary.js';
29
+
30
+ /** The default graph: the model. */
31
+ const MODEL_GRAPH = DataFactory.defaultGraph() as unknown as NamedNode;
32
+
33
+ /** A presentation context's key in a look's name: `shortHash`'s 8 hex digits. */
34
+ const CONTEXT_KEY = /[0-9a-f]{8}/;
35
+
36
+ /** What a look's style says as a style: its values — and what a concept's look never says, a base or a set. */
37
+ const STYLE_PREDICATES = new Set<string>([...APPEARANCE_KEYS.map((key) => APPEARANCE_PREDICATES[key]), IRI.basedOn, IRI.inStyleSet]);
38
+
39
+ /** One look a concept has of its own. */
40
+ export interface ConceptLook {
41
+ /** The presentation context it is for; for every context when absent — the saved look. */
42
+ context?: string;
43
+ /** The style that holds it. */
44
+ iri: string;
45
+ /** Its values. */
46
+ look: Appearance;
47
+ }
48
+
49
+ /** Every look `iri` has of its own: for every context first, then by context. */
50
+ export function conceptLooksOf(store: RdfStore, iri: string): ConceptLook[] {
51
+ const looks: ConceptLook[] = [];
52
+ for (const q of store.getQuads(nn(iri), T.conceptStyle, null, MODEL_GRAPH)) {
53
+ if (q.object.termType === 'Literal') continue;
54
+ const context = store.getQuads(q.object as NamedNode, T.inPresentationContext, null, MODEL_GRAPH)[0]?.object.value;
55
+ looks.push({ iri: q.object.value, look: lookOfStyle(store, q.object), ...(context ? { context } : {}) });
56
+ }
57
+ return looks.sort((a, b) => (a.context ? 1 : 0) - (b.context ? 1 : 0) || (a.context ?? '').localeCompare(b.context ?? ''));
58
+ }
59
+
60
+ /** `iri`'s look for `context` — for every context, its saved look, when absent; `undefined` when it has none. */
61
+ export function conceptLookFor(store: RdfStore, iri: string, context: string | undefined): ConceptLook | undefined {
62
+ return conceptLooksOf(store, iri).find((look) => look.context === context);
63
+ }
64
+
65
+ /** `iri`'s saved look: its look for every context, which its diagram elements take by basing their style on it. */
66
+ export function savedLookOf(store: RdfStore, iri: string): ConceptLook | undefined {
67
+ return conceptLookFor(store, iri, undefined);
68
+ }
69
+
70
+ /** `iri`'s looks for each presentation context, by context — what a diagram element based on its saved look is drawn with there. */
71
+ export function contextLooksOf(store: RdfStore, iri: string): Record<string, Appearance> | undefined {
72
+ const looks: Record<string, Appearance> = {};
73
+ for (const look of conceptLooksOf(store, iri)) {
74
+ if (look.context && APPEARANCE_KEYS.some((key) => look.look[key] !== undefined)) looks[look.context] = look.look;
75
+ }
76
+ return Object.keys(looks).length > 0 ? looks : undefined;
77
+ }
78
+
79
+ /** The IRI of `iri`'s look for `context` — for every context when absent: `{iri}/style`, `{iri}/style/{hash}`. */
80
+ export function conceptStyleIri(iri: string, context: string | undefined): string {
81
+ return context ? partIri(iri, 'style', shortHash(context)) : partIri(iri, 'style');
82
+ }
83
+
84
+ /**
85
+ * What changes `iri`'s look for `context` — for every context when absent — by `changes`, as `setAppearance`
86
+ * changes a diagram element's: a value sets it, `null` takes it away. Made when it has none — a look for a context
87
+ * with the saved look, saying nothing, where the concept has none, as what its diagram elements are based on. One
88
+ * another tool wrote as a blank node is named after the concept, keeping what it said. A look for a context emptied
89
+ * goes ({@link removeConceptLookChange}); the saved look emptied stays, saying nothing, while the concept has a look
90
+ * for a context, and goes otherwise, the styles based on it then based on nothing. Never based on another style: a
91
+ * `basedOn` in `changes` is not written.
92
+ */
93
+ export function conceptStyleChange(
94
+ store: RdfStore,
95
+ iri: string,
96
+ context: string | undefined,
97
+ changes: AppearanceChanges,
98
+ ): { remove: Quad[]; add: Quad[] } {
99
+ const concept = nn(iri);
100
+ const current = lookTerm(store, iri, context);
101
+ const style = current?.termType === 'NamedNode' ? (current as NamedNode) : nn(conceptStyleIri(iri, context));
102
+ // What it says now, and what it will say.
103
+ const said = current ? store.getQuads(current as NamedNode, null, null, MODEL_GRAPH) : [];
104
+ const values: Record<string, unknown> = { ...lookValues(current ? styleAppearance(store, current) : undefined) };
105
+ for (const key of APPEARANCE_KEYS) {
106
+ const value = changes[key];
107
+ if (value === undefined) continue;
108
+ if (value === null) delete values[key];
109
+ else if (appearanceTerm(key, value as NonNullable<Appearance[typeof key]>)) values[key] = value;
110
+ }
111
+ // Anything else it says — another tool's — stays with it; never a style it is based on, or a set.
112
+ const others = said.filter(
113
+ (q) => !STYLE_PREDICATES.has(q.predicate.value) && q.predicate.value !== IRI.rdfType && q.predicate.value !== IRI.inPresentationContext,
114
+ );
115
+ const remove: Quad[] = current ? [...store.getQuads(concept, T.conceptStyle, current as NamedNode, MODEL_GRAPH), ...said] : [];
116
+ const valueQuads = APPEARANCE_KEYS.flatMap((key) => {
117
+ const value = values[key];
118
+ const term = value === undefined ? undefined : appearanceTerm(key, value as NonNullable<Appearance[typeof key]>);
119
+ return term ? [triple(style, nn(APPEARANCE_PREDICATES[key]), term)] : [];
120
+ });
121
+ const add: Quad[] = [];
122
+ // A blank node another tool wrote, named now: what was based on it is based on the named one.
123
+ const renamed = () => {
124
+ if (!current || current.termType === 'NamedNode') return;
125
+ for (const q of store.getQuads(null, T.basedOn, current as unknown as NamedNode, MODEL_GRAPH)) {
126
+ remove.push(q);
127
+ add.push(triple(q.subject, T.basedOn, style));
128
+ }
129
+ };
130
+ if (valueQuads.length === 0 && others.length === 0) {
131
+ // Nothing left to say.
132
+ if (!current) return { remove: [], add: [] };
133
+ if (context) return removeConceptLookChange(store, iri, context);
134
+ // The saved look, what a look for a context is drawn through: kept, saying nothing, while there is one.
135
+ if (conceptLooksOf(store, iri).some((look) => look.context)) {
136
+ add.push(triple(concept, T.conceptStyle, style), triple(style, T.rdfType, T.Style));
137
+ renamed();
138
+ return netChange({ remove, add });
139
+ }
140
+ // No look left: what was based on it follows it to nothing.
141
+ const followers = detachAllChange(store, current, false);
142
+ return netChange({ remove: [...remove, ...followers.remove], add: followers.add });
143
+ }
144
+ add.push(
145
+ triple(concept, T.conceptStyle, style),
146
+ triple(style, T.rdfType, T.Style),
147
+ ...(context ? [triple(style, T.inPresentationContext, nn(context))] : []),
148
+ ...valueQuads,
149
+ ...others.map((q) => triple(style, q.predicate, q.object)),
150
+ );
151
+ // A look for a context is drawn through the saved look, which a diagram element is based on: made where it has none.
152
+ if (context && !lookTerm(store, iri, undefined)) {
153
+ const saved = nn(conceptStyleIri(iri, undefined));
154
+ add.push(triple(concept, T.conceptStyle, saved), triple(saved, T.rdfType, T.Style));
155
+ }
156
+ renamed();
157
+ // A look that keeps its name changes only in what differs.
158
+ return netChange({ remove, add });
159
+ }
160
+
161
+ /**
162
+ * What takes `iri`'s look for `context` away: what is based on its saved look is drawn there with the saved look's
163
+ * values, as it is where the concept has no look for a context. The saved look goes with it when it was the last
164
+ * look for a context and the saved look says nothing — the styles based on it then based on nothing.
165
+ */
166
+ export function removeConceptLookChange(store: RdfStore, iri: string, context: string): { remove: Quad[]; add: Quad[] } {
167
+ const current = lookTerm(store, iri, context);
168
+ if (!current) return { remove: [], add: [] };
169
+ const remove: Quad[] = [...store.getQuads(nn(iri), T.conceptStyle, current as NamedNode, MODEL_GRAPH), ...store.getQuads(current as NamedNode, null, null, MODEL_GRAPH)];
170
+ const add: Quad[] = [];
171
+ const saved = lookTerm(store, iri, undefined);
172
+ const lastForAContext = !conceptLooksOf(store, iri).some((look) => look.context && look.context !== context);
173
+ if (saved && lastForAContext && saysNothing(store, saved)) {
174
+ const followers = detachAllChange(store, saved, false);
175
+ remove.push(...store.getQuads(nn(iri), T.conceptStyle, saved as NamedNode, MODEL_GRAPH), ...store.getQuads(saved as NamedNode, null, null, MODEL_GRAPH), ...followers.remove);
176
+ add.push(...followers.add);
177
+ }
178
+ return netChange({ remove, add });
179
+ }
180
+
181
+ /**
182
+ * What deletes `iri`'s own look as a whole — for every context and for each: the styles based on it keep what it
183
+ * gave them, in every context (detached, meta's DD-47), so its diagram elements look as they did; then it goes.
184
+ */
185
+ export function deleteConceptLookChange(store: RdfStore, iri: string): { remove: Quad[]; add: Quad[] } {
186
+ const saved = lookTerm(store, iri, undefined);
187
+ const followers = saved ? detachAllChange(store, saved) : { remove: [], add: [] };
188
+ const remove: Quad[] = [...followers.remove];
189
+ for (const q of store.getQuads(nn(iri), T.conceptStyle, null, MODEL_GRAPH)) {
190
+ remove.push(q);
191
+ if (q.object.termType !== 'Literal') remove.push(...store.getQuads(q.object as NamedNode, null, null, MODEL_GRAPH));
192
+ }
193
+ return netChange({ remove, add: followers.add });
194
+ }
195
+
196
+ /**
197
+ * The quads of `iri`'s own looks that no other concept names as its look: what goes with the concept when it is
198
+ * deleted (`cascade.ts`, `ViewManager.collectViewQuads`). Its `arch-vis:conceptStyle` statements are its own
199
+ * triples, collected with them.
200
+ */
201
+ export function conceptStyleQuads(store: RdfStore, iri: string): Quad[] {
202
+ const quads: Quad[] = [];
203
+ for (const q of store.getQuads(nn(iri), T.conceptStyle, null, MODEL_GRAPH)) {
204
+ if (q.object.termType === 'Literal' || store.getQuads(null, T.conceptStyle, q.object as NamedNode, MODEL_GRAPH).length > 1) continue;
205
+ quads.push(...store.getQuads(q.object as NamedNode, null, null, MODEL_GRAPH));
206
+ }
207
+ return quads;
208
+ }
209
+
210
+ /** Whether `style` is `iri`'s own look by its name, either way a part is joined: `{iri}/style`, `{iri}/style/{hash}`. */
211
+ export function isConceptStyleNamed(iri: string, style: string): boolean {
212
+ return isPartNamed(iri, style, 'style', CONTEXT_KEY);
213
+ }
214
+
215
+ /** Whether a style says nothing but what it is and the context it is for. */
216
+ function saysNothing(store: RdfStore, style: Term): boolean {
217
+ return store
218
+ .getQuads(style as NamedNode, null, null, MODEL_GRAPH)
219
+ .every((q) => q.predicate.value === IRI.rdfType || q.predicate.value === IRI.inPresentationContext);
220
+ }
221
+
222
+ /** The style that holds `iri`'s look for `context` — a named one first, should another tool have written two. */
223
+ function lookTerm(store: RdfStore, iri: string, context: string | undefined): Term | undefined {
224
+ const found = store
225
+ .getQuads(nn(iri), T.conceptStyle, null, MODEL_GRAPH)
226
+ .map((q) => q.object)
227
+ .filter((style) => style.termType !== 'Literal')
228
+ .filter((style) => store.getQuads(style as NamedNode, T.inPresentationContext, null, MODEL_GRAPH)[0]?.object.value === context);
229
+ return found.find((style) => style.termType === 'NamedNode' && isConceptStyleNamed(iri, style.value)) ?? found[0];
230
+ }
@@ -57,6 +57,17 @@ export interface LabelExpressionInfo {
57
57
  export interface NodeInfo {
58
58
  /** How it looks in each presentation context it has a style for (core-vis 0.7), over {@link appearance}. */
59
59
  contextAppearances?: Record<string, Appearance>;
60
+ /**
61
+ * The looks for every presentation context of the styles its styles are based on (core-vis 0.11's
62
+ * `arch-vis:basedOn`): a style set's named style, its concept's saved look — by the based-on style's IRI. With
63
+ * {@link basedOnContextLooks}, what `drawnLook` fills its own styles in from.
64
+ */
65
+ basedOnLooks?: Record<string, Appearance>;
66
+ /**
67
+ * Their looks for each presentation context, by the based-on style's IRI, then the context's: a named style's — the
68
+ * styles of its set based on it, each for a context — its concept's own looks for each (`arch-vis:conceptStyle`).
69
+ */
70
+ basedOnContextLooks?: Record<string, Record<string, Appearance>>;
60
71
  /** What its label says, as its own style gives it: one expression a presentation context, one for every context. */
61
72
  labelExpressions?: LabelExpressionInfo[];
62
73
  nodeIri: string;
@@ -122,6 +133,10 @@ export interface FigureColours {
122
133
  export interface LinkInfo {
123
134
  /** How the line looks in each presentation context it has a style for (core-vis 0.7), over {@link appearance}. */
124
135
  contextAppearances?: Record<string, Appearance>;
136
+ /** The looks its styles are based on, by IRI (core-vis 0.11), as a node's {@link NodeInfo.basedOnLooks}. */
137
+ basedOnLooks?: Record<string, Appearance>;
138
+ /** Their looks for each presentation context (core-vis 0.11), as a node's {@link NodeInfo.basedOnContextLooks}. */
139
+ basedOnContextLooks?: Record<string, Record<string, Appearance>>;
125
140
  linkIri: string;
126
141
  relationshipIri: string;
127
142
  /** What the link starts at: a node, or the link of the relationship it starts at. */
@@ -339,7 +354,10 @@ export interface ViewManager {
339
354
  * element's placement, a figure) or a link (a relationship's line, a line
340
355
  * from a note), by its IRI. `null` takes a value back to the default. A
341
356
  * style it shares, or one another tool wrote as a blank node, is copied to
342
- * its own first, so the change is to it alone.
357
+ * its own first, so the change is to it alone — but a style set's named
358
+ * style, or its concept's saved look, is based on (core-vis 0.11), so it
359
+ * keeps following it. `basedOn` names the style its values are taken from
360
+ * where it sets none; `null` bases it on nothing.
343
361
  */
344
362
  setAppearance?(viewIri: string, iri: string, changes: AppearanceChanges, context?: string): void;
345
363
  /**
@@ -49,7 +49,7 @@ export interface LayoutReport {
49
49
  }
50
50
 
51
51
  /** The kinds of resource with an identity of their own: `{ns}{kind}/{id}` (the guide's kinds table). */
52
- const KINDS = 'element|relationship|view|folder|decision|documentation|stakeholder|provenance';
52
+ const KINDS = 'element|relationship|view|folder|styleset|decision|documentation|stakeholder|provenance';
53
53
  const IN_LAYOUT = new RegExp(`^(?:model(?:/.*)?|graph/[^/#]+|(?:${KINDS})/[^/#].*)$`);
54
54
  /**
55
55
  * What la-gram minted before DD-41: `{ns}element-{uuid}`, `{ns}node-{uuid}`, and their parts, `{node}-style`;
@@ -64,7 +64,10 @@ const PATH = /^(?:[A-Za-z0-9\-._~!$&'()*+,;=:@/]|%[0-9A-Fa-f]{2}|[^\x00-\x7F])*$
64
64
  const FRAGMENT = /^(?:[A-Za-z0-9\-._~!$&'()*+,;=:@/?#]|%[0-9A-Fa-f]{2}|[^\x00-\x7F])*$/;
65
65
 
66
66
  const VANN_URI = NAMESPACES.vann + 'preferredNamespaceUri';
67
- /** What names a part from its owner (DD-41's table): `{shape}-style`, `{shape}-label`, `{concept}/name/…`, `{folder}/item/…`. */
67
+ /**
68
+ * What names a part from its owner (DD-41's table): `{shape}-style`, `{shape}-label`, `{concept}/name/…`,
69
+ * `{concept}/style/…` (core-vis 0.11), `{folder}/item/…`.
70
+ */
68
71
  const PART_OF = new Set<string>([
69
72
  IRI.visStyle,
70
73
  IRI.visLabel,
@@ -72,8 +75,11 @@ const PART_OF = new Set<string>([
72
75
  IRI.skosxlAltLabel,
73
76
  IRI.prefVisNotation,
74
77
  IRI.altVisNotation,
78
+ IRI.conceptStyle,
75
79
  ...SCHEMA_ITEM_LIST_ELEMENT.map((t) => t.value),
76
80
  ]);
81
+ /** What names its owner from a part: a style set's style says the set it is in, `{set}/style/{id}` (core-vis 0.11). */
82
+ const OWNED_BY = new Set<string>([IRI.inStyleSet]);
77
83
  const NODE_TYPES = new Set<string>([IRI.ArchNode, IRI.ContainerNode, IRI.LabelNode, IRI.ViewReferenceNode]);
78
84
  /** A shape's fragment in its view: a line's `link-{id}`, a node's `node-{id}`, either for a shape of no known type. */
79
85
  const SHAPE_NAME = { link: /^link-[^/#]+$/, node: /^node-[^/#]+$/, either: /^(?:node|link)-[^/#]+$/ };
@@ -115,6 +121,7 @@ export function layoutReport(quads: readonly Quad[]): LayoutReport | undefined {
115
121
  else if (p === IRI.rdfFirst) firsts.set(s, o);
116
122
  else if (p === IRI.rdfRest) rests.set(s, o);
117
123
  if (PART_OF.has(p)) add(owners, o, s);
124
+ if (OWNED_BY.has(p)) add(owners, s, o);
118
125
  if (p === IRI.visLabel) labels.add(o);
119
126
  }
120
127
  // A route's cells and points are the line's.