@pacem/pacem-foundation 1.0.6-ricci → 2.0.0-abel
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.
- package/dist/browser/pacem-foundation.js +1429 -87
- package/dist/browser/pacem-foundation.js.map +1 -1
- package/dist/browser/pacem-foundation.min.js +2 -2
- package/dist/bundle/pacem-foundation.min.mjs +11 -8
- package/dist/bundle/pacem-foundation.mjs +1630 -95
- package/dist/bundle/pacem-foundation.mjs.map +4 -4
- package/dist/docs/pacem-foundation.json +2763 -694
- package/dist/esm/array-extensions.js +1 -1
- package/dist/esm/arrays.js +1 -1
- package/dist/esm/blobs.js +1 -1
- package/dist/esm/browser.js +1 -1
- package/dist/esm/colors.js +1 -1
- package/dist/esm/dates.js +1 -1
- package/dist/esm/deepmerger.js +1 -1
- package/dist/esm/geom.js +1 -1
- package/dist/esm/history-svc.js +1 -1
- package/dist/esm/imaging.js +1 -1
- package/dist/esm/index-compile-markdown.js +1 -1
- package/dist/esm/index-compile.js +6 -1
- package/dist/esm/index-iife.js +1 -1
- package/dist/esm/index-root.js +1 -1
- package/dist/esm/index.js +1 -1
- package/dist/esm/keygenerator.js +1 -1
- package/dist/esm/matrix2d.js +1 -1
- package/dist/esm/null-checker.js +1 -1
- package/dist/esm/number-extensions.js +1 -1
- package/dist/esm/numbers.js +1 -1
- package/dist/esm/rect.js +1 -1
- package/dist/esm/strings.js +1 -1
- package/package.json +1 -1
- package/typings/index.d.ts +256 -1
package/dist/esm/arrays.js
CHANGED
package/dist/esm/blobs.js
CHANGED
package/dist/esm/browser.js
CHANGED
package/dist/esm/colors.js
CHANGED
package/dist/esm/dates.js
CHANGED
package/dist/esm/deepmerger.js
CHANGED
package/dist/esm/geom.js
CHANGED
package/dist/esm/history-svc.js
CHANGED
package/dist/esm/imaging.js
CHANGED
|
@@ -1,8 +1,13 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* @pacem/pacem-foundation
|
|
2
|
+
* @pacem/pacem-foundation v2.0.0-abel (https://js.pacem.it)
|
|
3
3
|
* Pacem (https://pacem.it)
|
|
4
4
|
* Licensed under Apache-2.0
|
|
5
5
|
*/
|
|
6
6
|
import * as Markdown from './index-compile-markdown';
|
|
7
7
|
export { Markdown };
|
|
8
8
|
export * from './compile/parser';
|
|
9
|
+
export * from './compile/syntax/types';
|
|
10
|
+
export * from './compile/syntax/registry';
|
|
11
|
+
export * from './compile/syntax/scanner';
|
|
12
|
+
export * from './compile/syntax/highlight';
|
|
13
|
+
export * from './compile/syntax/builtins';
|
package/dist/esm/index-iife.js
CHANGED
package/dist/esm/index-root.js
CHANGED
package/dist/esm/index.js
CHANGED
package/dist/esm/keygenerator.js
CHANGED
package/dist/esm/matrix2d.js
CHANGED
package/dist/esm/null-checker.js
CHANGED
package/dist/esm/numbers.js
CHANGED
package/dist/esm/rect.js
CHANGED
package/dist/esm/strings.js
CHANGED
package/package.json
CHANGED
package/typings/index.d.ts
CHANGED
|
@@ -101,6 +101,12 @@ export declare class Blobs {
|
|
|
101
101
|
/** Text encodings supported by {@link Blobs.textToBlob}. */
|
|
102
102
|
declare type BlobTextEncoding = 'utf-8' | 'utf-16' | 'utf-16be' | 'utf-16le' | 'iso-8859-1' | 'ascii';
|
|
103
103
|
|
|
104
|
+
/** A {@link Syntax} shipped with foundation: its name, and its base syntax if any, are {@link SyntaxName}s. */
|
|
105
|
+
declare interface BuiltinSyntax extends Syntax {
|
|
106
|
+
name: SyntaxName;
|
|
107
|
+
extends?: SyntaxName;
|
|
108
|
+
}
|
|
109
|
+
|
|
104
110
|
/** Represents a color in the CIE 1931 XYZ color space. */
|
|
105
111
|
export declare interface CieXYZ {
|
|
106
112
|
readonly x: number;
|
|
@@ -207,7 +213,28 @@ declare namespace Compile {
|
|
|
207
213
|
Token,
|
|
208
214
|
Lexer,
|
|
209
215
|
Renderer,
|
|
210
|
-
Parser
|
|
216
|
+
Parser,
|
|
217
|
+
LexicalMatchRule,
|
|
218
|
+
LexicalIncludeRule,
|
|
219
|
+
LexicalRule,
|
|
220
|
+
LexicalCondition,
|
|
221
|
+
LexicalSyntax,
|
|
222
|
+
SyntaxName,
|
|
223
|
+
SyntaxNameOrAlias,
|
|
224
|
+
Syntax,
|
|
225
|
+
BuiltinSyntax,
|
|
226
|
+
SyntaxToken,
|
|
227
|
+
SyntaxTokenType,
|
|
228
|
+
Syntaxes,
|
|
229
|
+
Scanner,
|
|
230
|
+
DefaultHighlightClasses,
|
|
231
|
+
HighlightRenderer,
|
|
232
|
+
JavaScriptSyntax,
|
|
233
|
+
PacemBindingSyntax,
|
|
234
|
+
MarkupSyntax,
|
|
235
|
+
CSharpSyntax,
|
|
236
|
+
CSyntax,
|
|
237
|
+
JsonSyntax
|
|
211
238
|
}
|
|
212
239
|
}
|
|
213
240
|
export { Compile }
|
|
@@ -222,6 +249,20 @@ declare namespace Compile_2 {
|
|
|
222
249
|
}
|
|
223
250
|
}
|
|
224
251
|
|
|
252
|
+
/**
|
|
253
|
+
* C# vocabulary: XML doc comments (`doc-comment`), comments, preprocessor directives, strings (regular, verbatim, raw,
|
|
254
|
+
* interpolated with nested `{…}` expressions), chars, numbers (with suffixes), identifiers (`@verbatim` included),
|
|
255
|
+
* keywords (contextual ones included, not after `.`/`?.`), brackets, punctuation and operators.
|
|
256
|
+
*/
|
|
257
|
+
declare const CSharpSyntax: BuiltinSyntax;
|
|
258
|
+
|
|
259
|
+
/**
|
|
260
|
+
* C/C++ vocabulary: comments (`/** … *\/` and `///` as `doc-comment`), preprocessor directives (with their `<header>`),
|
|
261
|
+
* strings (raw `R"x(…)x"` and prefixed ones included), chars, numbers (with suffixes/separators), identifiers, keywords
|
|
262
|
+
* (C and C++), brackets, punctuation and operators.
|
|
263
|
+
*/
|
|
264
|
+
declare const CSyntax: BuiltinSyntax;
|
|
265
|
+
|
|
225
266
|
/** Date parsing and arithmetic utilities. */
|
|
226
267
|
export declare class Dates {
|
|
227
268
|
/**
|
|
@@ -291,6 +332,9 @@ export declare class DeepMerger {
|
|
|
291
332
|
static merge<S extends PlainObject, T extends PlainObject>(source: S, target?: T): T & S;
|
|
292
333
|
}
|
|
293
334
|
|
|
335
|
+
/** Default token type → CSS class mapping, matching the `code-*` classes styled by the theme (see `ui/markdown.css`). */
|
|
336
|
+
declare const DefaultHighlightClasses: Readonly<Record<string, string>>;
|
|
337
|
+
|
|
294
338
|
/**
|
|
295
339
|
* Detects the browser name and version from a user-agent string.
|
|
296
340
|
* @param userAgent User-agent string to parse (defaults to `navigator.userAgent`).
|
|
@@ -329,6 +373,20 @@ declare type ExtraRule = (Compile_2.Rule | {
|
|
|
329
373
|
lang: string;
|
|
330
374
|
});
|
|
331
375
|
|
|
376
|
+
/**
|
|
377
|
+
* Renders a token stream (typically produced by the {@link Scanner}) as HTML: every token's `raw` text is HTML-encoded and,
|
|
378
|
+
* when its type has a mapped class, wrapped in a `<span class="…">`.
|
|
379
|
+
*/
|
|
380
|
+
declare class HighlightRenderer implements Renderer {
|
|
381
|
+
private readonly _classes;
|
|
382
|
+
/**
|
|
383
|
+
* @param _classes Token type → CSS class mapping (defaults to {@link DefaultHighlightClasses}).
|
|
384
|
+
*/
|
|
385
|
+
constructor(_classes?: Readonly<Record<string, string>>);
|
|
386
|
+
render(tree: Token[]): string;
|
|
387
|
+
private _renderToken;
|
|
388
|
+
}
|
|
389
|
+
|
|
332
390
|
/** Grants undo/redo functionalities for given state. */
|
|
333
391
|
export declare class HistoryService<TState = any> {
|
|
334
392
|
#private;
|
|
@@ -406,6 +464,20 @@ export declare type ImagingResizeOptions = {
|
|
|
406
464
|
background?: string;
|
|
407
465
|
};
|
|
408
466
|
|
|
467
|
+
/**
|
|
468
|
+
* JavaScript vocabulary, TypeScript superset: comments (JSDoc as `doc-comment`), strings, template literals with nested
|
|
469
|
+
* `${…}` expressions, regular expression literals (told from divisions by the previous significant token), numbers
|
|
470
|
+
* (hex/binary/octal/BigInt/separators), identifiers (`#private` included), keywords (JS + TS, not after `.`/`?.`),
|
|
471
|
+
* brackets, punctuation and operators.
|
|
472
|
+
*/
|
|
473
|
+
declare const JavaScriptSyntax: BuiltinSyntax;
|
|
474
|
+
|
|
475
|
+
/**
|
|
476
|
+
* JSON vocabulary (JSONC and JSON5-ish tolerant: comments, single quotes and trailing commas are recognized):
|
|
477
|
+
* object keys are `attribute`s, values `string`/`number`/`keyword` (`true`, `false`, `null`).
|
|
478
|
+
*/
|
|
479
|
+
declare const JsonSyntax: BuiltinSyntax;
|
|
480
|
+
|
|
409
481
|
/** Unique key/id generation utilities. */
|
|
410
482
|
export declare class Keys {
|
|
411
483
|
#private;
|
|
@@ -438,6 +510,71 @@ declare interface Lexer {
|
|
|
438
510
|
tokenize(input: string, grammar: Rule[]): Token[];
|
|
439
511
|
}
|
|
440
512
|
|
|
513
|
+
/** Predicate on the previous significant token, e.g. to tell a JavaScript regular expression literal from a division. */
|
|
514
|
+
declare interface LexicalCondition {
|
|
515
|
+
/** The previous token must have one of these types. */
|
|
516
|
+
previousTypes?: string[];
|
|
517
|
+
/** The previous token must not have any of these types. */
|
|
518
|
+
previousNotTypes?: string[];
|
|
519
|
+
/** The previous token's raw text must be one of these. */
|
|
520
|
+
previousTexts?: string[];
|
|
521
|
+
/** The previous token's raw text must not be any of these. */
|
|
522
|
+
previousNotTexts?: string[];
|
|
523
|
+
}
|
|
524
|
+
|
|
525
|
+
/** Includes (at compile time) the rules of another state of the same syntax, in place. */
|
|
526
|
+
declare interface LexicalIncludeRule {
|
|
527
|
+
include: string;
|
|
528
|
+
}
|
|
529
|
+
|
|
530
|
+
/**
|
|
531
|
+
* A lexical rule of a {@link Syntax} state: a regular expression (source string, compiled *sticky*) recognizing a token
|
|
532
|
+
* at the current position, plus the state transitions to apply once matched.
|
|
533
|
+
* Transitions are applied in this order: `pop`, `next`, `push`, `embed`.
|
|
534
|
+
*/
|
|
535
|
+
declare interface LexicalMatchRule {
|
|
536
|
+
/** Regular expression source (no delimiters), matched at the current position. */
|
|
537
|
+
match: string;
|
|
538
|
+
/** Extra regular expression flags (e.g. `'i'`); the sticky flag is implied. */
|
|
539
|
+
flags?: string;
|
|
540
|
+
/**
|
|
541
|
+
* Type of the produced token or, when an array, one type per capture group (groups are expected to cover the
|
|
542
|
+
* whole match: uncovered characters become `text` tokens).
|
|
543
|
+
*/
|
|
544
|
+
type: string | string[];
|
|
545
|
+
/** Condition on the previous *significant* token (see {@link LexicalSyntax.insignificant}) for the rule to apply. */
|
|
546
|
+
when?: LexicalCondition;
|
|
547
|
+
/** Pops the current state (`true` = 1, or the number of states to pop). */
|
|
548
|
+
pop?: boolean | number;
|
|
549
|
+
/** Replaces the current state. */
|
|
550
|
+
next?: string;
|
|
551
|
+
/** Pushes a state of the same syntax. */
|
|
552
|
+
push?: string;
|
|
553
|
+
/** Pushes the start state of another (registered) syntax. */
|
|
554
|
+
embed?: SyntaxNameOrAlias;
|
|
555
|
+
/** With `embed`: regular expression source that, as soon as it matches, pops the embedded syntax (without consuming input). */
|
|
556
|
+
until?: string;
|
|
557
|
+
}
|
|
558
|
+
|
|
559
|
+
/** A rule of a {@link LexicalSyntax} state. */
|
|
560
|
+
declare type LexicalRule = LexicalMatchRule | LexicalIncludeRule;
|
|
561
|
+
|
|
562
|
+
/** Lexical part of a {@link Syntax}: a state machine of ordered rules, Monarch/TextMate-like. */
|
|
563
|
+
declare interface LexicalSyntax {
|
|
564
|
+
/** Initial state (defaults to `'root'`). */
|
|
565
|
+
start?: string;
|
|
566
|
+
/** Ordered rules per state: the first rule matching at the current position wins. */
|
|
567
|
+
states: Record<string, LexicalRule[]>;
|
|
568
|
+
/** Keyword lists, by token type: tokens of a {@link keywordSources} type whose text is listed get that type instead. */
|
|
569
|
+
keywords?: Record<string, string[]>;
|
|
570
|
+
/** Token types keywords are looked up for (defaults to `['identifier']`). */
|
|
571
|
+
keywordSources?: string[];
|
|
572
|
+
/** Previous significant token texts preventing the keyword lookup (e.g. `'.'`, so that `obj.type` stays an identifier). */
|
|
573
|
+
keywordExceptAfter?: string[];
|
|
574
|
+
/** Token types ignored when evaluating {@link LexicalCondition}s (defaults to spaces, newlines and comments). */
|
|
575
|
+
insignificant?: string[];
|
|
576
|
+
}
|
|
577
|
+
|
|
441
578
|
declare namespace Markdown {
|
|
442
579
|
export {
|
|
443
580
|
ExtraRule,
|
|
@@ -445,6 +582,12 @@ declare namespace Markdown {
|
|
|
445
582
|
}
|
|
446
583
|
}
|
|
447
584
|
|
|
585
|
+
/**
|
|
586
|
+
* Markup (HTML/XML) vocabulary: comments, doctypes/CDATA, tags (`tag`/`tagname`), attributes, quoted values (Pacem
|
|
587
|
+
* `{{ … }}` bindings tokenized with `pacem-binding`), entities, text, and `<script>` bodies tokenized with `javascript`.
|
|
588
|
+
*/
|
|
589
|
+
declare const MarkupSyntax: BuiltinSyntax;
|
|
590
|
+
|
|
448
591
|
/** Represents the typical matrix for 2D graphics (css, svg, ...) */
|
|
449
592
|
export declare interface Matrix2D {
|
|
450
593
|
readonly a: number;
|
|
@@ -581,6 +724,18 @@ export declare class Numbers {
|
|
|
581
724
|
static rebase(v: number | string, from: number, to: number): string;
|
|
582
725
|
}
|
|
583
726
|
|
|
727
|
+
/**
|
|
728
|
+
* Pacem binding-expression vocabulary (the content of `{{ … }}` attributes): JavaScript plus the special tokens
|
|
729
|
+
* resolved by core's `Expression`:
|
|
730
|
+
* - `binding-host`: `:host` (followed by `.`);
|
|
731
|
+
* - `binding-host-property`: `::name`;
|
|
732
|
+
* - `binding-item`: `^item`, `^^item`, … (repeater item, n levels up);
|
|
733
|
+
* - `binding-index`: `^index`, `^^index`, …;
|
|
734
|
+
* - `binding-element`: `#id` (element reference);
|
|
735
|
+
* - `binding-this`: `$this` / `this` (the bound element).
|
|
736
|
+
*/
|
|
737
|
+
declare const PacemBindingSyntax: BuiltinSyntax;
|
|
738
|
+
|
|
584
739
|
/**
|
|
585
740
|
* Extracts all the floating point numbers found in a string (e.g. `"10px 20px"` => `[10, 20]`).
|
|
586
741
|
* @param input String to parse.
|
|
@@ -753,6 +908,22 @@ declare interface Rule {
|
|
|
753
908
|
exec: (input: string, lexer?: Lexer) => Token[];
|
|
754
909
|
}
|
|
755
910
|
|
|
911
|
+
/**
|
|
912
|
+
* Language-agnostic lexical engine: tokenizes a source text according to a {@link Syntax} vocabulary.
|
|
913
|
+
* - lossless: concatenating the tokens' `raw` reproduces the source exactly;
|
|
914
|
+
* - linear: a single cursor and sticky regular expressions (compiled once per syntax);
|
|
915
|
+
* - error tolerant: unrecognized characters become `text` tokens, it never throws.
|
|
916
|
+
*/
|
|
917
|
+
declare class Scanner {
|
|
918
|
+
/**
|
|
919
|
+
* Tokenizes `source`.
|
|
920
|
+
* @param source Source text.
|
|
921
|
+
* @param syntax A {@link Syntax} or the name/alias of a registered one (see {@link Syntaxes}); an unknown one yields a single `text` token.
|
|
922
|
+
* @returns The lossless, positioned token stream.
|
|
923
|
+
*/
|
|
924
|
+
tokenize(source: string, syntax: Syntax | SyntaxNameOrAlias): SyntaxToken[];
|
|
925
|
+
}
|
|
926
|
+
|
|
756
927
|
/** Represents a 2D size (width/height). */
|
|
757
928
|
export declare interface Size {
|
|
758
929
|
width: number;
|
|
@@ -805,6 +976,90 @@ export declare class Strings {
|
|
|
805
976
|
static hash(input: string, algo?: HashAlgorithmIdentifier): Promise<string>;
|
|
806
977
|
}
|
|
807
978
|
|
|
979
|
+
/**
|
|
980
|
+
* A language vocabulary: everything the language-agnostic {@link Scanner} needs to tokenize a source text.
|
|
981
|
+
* It is plain, JSON-serializable data (regular expressions are strings), so vocabularies can be shipped or fetched as data
|
|
982
|
+
* and registered at runtime (see {@link Syntaxes}).
|
|
983
|
+
*/
|
|
984
|
+
declare interface Syntax {
|
|
985
|
+
/** Unique (case-insensitive) name, e.g. `'javascript'`. */
|
|
986
|
+
name: string;
|
|
987
|
+
/** Alternative names, e.g. `['js', 'ts', 'typescript']`. */
|
|
988
|
+
aliases?: string[];
|
|
989
|
+
/**
|
|
990
|
+
* Name of a base syntax: states are merged (this syntax's rules come first), keywords are merged too, and `include`s
|
|
991
|
+
* are resolved against the merged states.
|
|
992
|
+
*/
|
|
993
|
+
extends?: SyntaxNameOrAlias;
|
|
994
|
+
lexical: LexicalSyntax;
|
|
995
|
+
}
|
|
996
|
+
|
|
997
|
+
/**
|
|
998
|
+
* Registry of the {@link Syntax} vocabularies known to the {@link Scanner}, by (case-insensitive) name and aliases.
|
|
999
|
+
* The built-in vocabularies (see {@link SyntaxName}) are registered upfront; more can be
|
|
1000
|
+
* registered at runtime, e.g. after fetching them as JSON.
|
|
1001
|
+
*/
|
|
1002
|
+
declare class Syntaxes {
|
|
1003
|
+
/**
|
|
1004
|
+
* Registers (or replaces) a syntax under its name and aliases.
|
|
1005
|
+
* @param syntax The vocabulary to register.
|
|
1006
|
+
*/
|
|
1007
|
+
static register(syntax: Syntax): void;
|
|
1008
|
+
/**
|
|
1009
|
+
* Gets a registered syntax by name or alias.
|
|
1010
|
+
* @param nameOrAlias Case-insensitive name or alias (e.g. `'ts'`).
|
|
1011
|
+
* @returns The syntax, or `null` when unknown.
|
|
1012
|
+
*/
|
|
1013
|
+
static get(nameOrAlias: SyntaxNameOrAlias): Syntax | null;
|
|
1014
|
+
/** Names (and aliases) of every registered syntax. */
|
|
1015
|
+
static names(): string[];
|
|
1016
|
+
}
|
|
1017
|
+
|
|
1018
|
+
/** Names of the built-in vocabularies, registered as soon as the compile module loads (see {@link Syntaxes}). */
|
|
1019
|
+
declare type SyntaxName = 'javascript' | 'pacem-binding' | 'markup' | 'csharp' | 'c' | 'json';
|
|
1020
|
+
|
|
1021
|
+
/**
|
|
1022
|
+
* Name or alias of a registered syntax: a built-in {@link SyntaxName} (autocompleted), or any other name/alias
|
|
1023
|
+
* registered at runtime (`string & {}` keeps the literals from collapsing into `string`).
|
|
1024
|
+
*/
|
|
1025
|
+
declare type SyntaxNameOrAlias = SyntaxName | (string & {});
|
|
1026
|
+
|
|
1027
|
+
/** A {@link Token} produced by the {@link Scanner}: lossless (`raw` is the exact source slice) and positioned. */
|
|
1028
|
+
declare interface SyntaxToken extends Token {
|
|
1029
|
+
/** Character offset in the source. */
|
|
1030
|
+
readonly index: number;
|
|
1031
|
+
/** 1-based line. */
|
|
1032
|
+
readonly line: number;
|
|
1033
|
+
/** 1-based column. */
|
|
1034
|
+
readonly column: number;
|
|
1035
|
+
/** Nesting depth of the lexical state stack (0 = start state of the outermost syntax). */
|
|
1036
|
+
readonly depth: number;
|
|
1037
|
+
/** Name of the syntax that produced the token (differs from the outermost one inside embedded syntaxes). */
|
|
1038
|
+
readonly syntax: SyntaxNameOrAlias;
|
|
1039
|
+
}
|
|
1040
|
+
|
|
1041
|
+
/** Token types shared by the built-in vocabularies (vocabularies may add their own). */
|
|
1042
|
+
declare enum SyntaxTokenType {
|
|
1043
|
+
Text = "text",
|
|
1044
|
+
Space = "space",
|
|
1045
|
+
Newline = "newline",
|
|
1046
|
+
Comment = "comment",
|
|
1047
|
+
DocComment = "doc-comment",
|
|
1048
|
+
Keyword = "keyword",
|
|
1049
|
+
Identifier = "identifier",
|
|
1050
|
+
String = "string",
|
|
1051
|
+
Regex = "regex",
|
|
1052
|
+
Number = "number",
|
|
1053
|
+
Bracket = "bracket",
|
|
1054
|
+
Punctuation = "punctuation",
|
|
1055
|
+
Operator = "operator",
|
|
1056
|
+
Preprocessor = "preprocessor",
|
|
1057
|
+
Tag = "tag",
|
|
1058
|
+
TagName = "tagname",
|
|
1059
|
+
Attribute = "attribute",
|
|
1060
|
+
Entity = "entity"
|
|
1061
|
+
}
|
|
1062
|
+
|
|
808
1063
|
/** A lexical token produced by tokenizing input against a grammar. */
|
|
809
1064
|
declare interface Token {
|
|
810
1065
|
/** Position (character offset) within the original input where this token starts, if known. */
|