notationWordOrigin function
String?
notationWordOrigin(
- String word, {
- Catalog? catalog,
- NotationVocabulary vocabulary = NotationVocabulary.core,
Where the meaning of word (a line's first word) is written: base (a
node type of the notation or the catalog, a statement: the renderer and
the parser implement it), code (a word of the page's frames the expander
writes out in Dart: App, Section, Nav…, or a line of another shape the
alias table names), the name of the dictionary vocabulary has it from
(a folder of definitions a caller gave: NotationVocabulary.dictionary),
or null (no word of the notation's: a design system's, a writer's,
unknown).
Implementation
String? notationWordOrigin(String word, {Catalog? catalog, NotationVocabulary vocabulary = NotationVocabulary.core}) {
if (word.isEmpty) return null;
if (vocabulary.dictionary[word] case final defs? when defs.isNotEmpty && !vocabulary.definitions.containsKey(word)) return defs.first.dictionary;
if (PageWords.words.contains(word)) return 'code';
const statements = {'state', 'project', 'if', 'else', 'each', 'for', 'key', 'every', 'node', 'document', 'let', 'derived', 'const', 'var', 'define', 'primitive', 'component'};
if (statements.contains(word)) return 'base';
final c = catalog ?? Catalog.current;
final lower = '${word[0].toLowerCase()}${word.substring(1)}';
if (notationTypes.containsKey(word) || (word[0] == word[0].toUpperCase() && c.widget(lower) != null)) return 'base';
return null;
}