@wdprlib/ast 2.0.0 → 2.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.
- package/dist/index.cjs +446 -1
- package/dist/index.d.cts +84 -13
- package/dist/index.d.ts +84 -13
- package/dist/index.js +446 -1
- package/package.json +4 -2
- package/src/constants.ts +12 -0
- package/src/css.ts +83 -0
- package/src/diagnostic.ts +104 -0
- package/src/element.ts +1309 -0
- package/src/expr-eval.ts +586 -0
- package/src/index.ts +123 -0
- package/src/position.ts +73 -0
- package/src/settings.ts +157 -0
package/dist/index.cjs
CHANGED
|
@@ -38,6 +38,7 @@ __export(exports_src, {
|
|
|
38
38
|
link: () => link,
|
|
39
39
|
lineBreak: () => lineBreak,
|
|
40
40
|
italics: () => italics,
|
|
41
|
+
isTruthy: () => isTruthy,
|
|
41
42
|
isStringContainerType: () => isStringContainerType,
|
|
42
43
|
isParagraphSafe: () => isParagraphSafe,
|
|
43
44
|
isHeaderType: () => isHeaderType,
|
|
@@ -45,13 +46,16 @@ __export(exports_src, {
|
|
|
45
46
|
isAlignType: () => isAlignType,
|
|
46
47
|
horizontalRule: () => horizontalRule,
|
|
47
48
|
heading: () => heading,
|
|
49
|
+
formatExprValue: () => formatExprValue,
|
|
50
|
+
evaluateExpression: () => evaluateExpression,
|
|
48
51
|
createSettings: () => createSettings,
|
|
49
52
|
createPosition: () => createPosition,
|
|
50
53
|
createPoint: () => createPoint,
|
|
51
54
|
container: () => container,
|
|
52
55
|
bold: () => bold,
|
|
53
56
|
STYLE_SLOT_PREFIX: () => STYLE_SLOT_PREFIX,
|
|
54
|
-
DEFAULT_SETTINGS: () => DEFAULT_SETTINGS
|
|
57
|
+
DEFAULT_SETTINGS: () => DEFAULT_SETTINGS,
|
|
58
|
+
CSS_LENGTH_UNITS: () => CSS_LENGTH_UNITS
|
|
55
59
|
});
|
|
56
60
|
module.exports = __toCommonJS(exports_src);
|
|
57
61
|
|
|
@@ -250,6 +254,447 @@ function isParagraphSafe(element) {
|
|
|
250
254
|
}
|
|
251
255
|
// packages/ast/src/constants.ts
|
|
252
256
|
var STYLE_SLOT_PREFIX = "\x00__IFTAGS_SLOT__";
|
|
257
|
+
// packages/ast/src/css.ts
|
|
258
|
+
var CSS_LENGTH_UNITS = [
|
|
259
|
+
"cqmax",
|
|
260
|
+
"cqmin",
|
|
261
|
+
"cqw",
|
|
262
|
+
"cqh",
|
|
263
|
+
"cqi",
|
|
264
|
+
"cqb",
|
|
265
|
+
"svmin",
|
|
266
|
+
"svmax",
|
|
267
|
+
"lvmin",
|
|
268
|
+
"lvmax",
|
|
269
|
+
"dvmin",
|
|
270
|
+
"dvmax",
|
|
271
|
+
"vmin",
|
|
272
|
+
"vmax",
|
|
273
|
+
"svw",
|
|
274
|
+
"svh",
|
|
275
|
+
"svi",
|
|
276
|
+
"svb",
|
|
277
|
+
"lvw",
|
|
278
|
+
"lvh",
|
|
279
|
+
"lvi",
|
|
280
|
+
"lvb",
|
|
281
|
+
"dvw",
|
|
282
|
+
"dvh",
|
|
283
|
+
"dvi",
|
|
284
|
+
"dvb",
|
|
285
|
+
"vw",
|
|
286
|
+
"vh",
|
|
287
|
+
"vi",
|
|
288
|
+
"vb",
|
|
289
|
+
"rcap",
|
|
290
|
+
"rem",
|
|
291
|
+
"rex",
|
|
292
|
+
"rch",
|
|
293
|
+
"ric",
|
|
294
|
+
"rlh",
|
|
295
|
+
"cap",
|
|
296
|
+
"em",
|
|
297
|
+
"ex",
|
|
298
|
+
"ch",
|
|
299
|
+
"ic",
|
|
300
|
+
"lh",
|
|
301
|
+
"cm",
|
|
302
|
+
"mm",
|
|
303
|
+
"in",
|
|
304
|
+
"pc",
|
|
305
|
+
"pt",
|
|
306
|
+
"px",
|
|
307
|
+
"q",
|
|
308
|
+
"%"
|
|
309
|
+
];
|
|
310
|
+
// packages/ast/src/expr-eval.ts
|
|
311
|
+
var FALSE_VALUES = new Set(["false", "null", "", "0"]);
|
|
312
|
+
function isTruthy(value) {
|
|
313
|
+
return !FALSE_VALUES.has(value.toLowerCase().trim());
|
|
314
|
+
}
|
|
315
|
+
var MAX_EXPRESSION_LENGTH = 256;
|
|
316
|
+
function isTruthyNum(n) {
|
|
317
|
+
return n !== 0 && !Number.isNaN(n);
|
|
318
|
+
}
|
|
319
|
+
function formatExprValue(n) {
|
|
320
|
+
return String(n);
|
|
321
|
+
}
|
|
322
|
+
function evaluateExpression(expr) {
|
|
323
|
+
try {
|
|
324
|
+
if (expr.length > MAX_EXPRESSION_LENGTH) {
|
|
325
|
+
return { success: false, error: "expression too long" };
|
|
326
|
+
}
|
|
327
|
+
if (expr.trim() === "") {
|
|
328
|
+
return { success: false, error: "empty expression" };
|
|
329
|
+
}
|
|
330
|
+
const tokens = tokenize(expr);
|
|
331
|
+
if (tokens.length <= 1) {
|
|
332
|
+
return { success: false, error: "empty expression" };
|
|
333
|
+
}
|
|
334
|
+
const parser = new ExprParser(tokens);
|
|
335
|
+
const result = parser.parse();
|
|
336
|
+
if (!Number.isFinite(result)) {
|
|
337
|
+
return { success: false, error: "division by zero" };
|
|
338
|
+
}
|
|
339
|
+
return { success: true, value: result };
|
|
340
|
+
} catch (e) {
|
|
341
|
+
const msg = e instanceof Error ? e.message : "unknown error";
|
|
342
|
+
return { success: false, error: msg };
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
function tokenize(expr) {
|
|
346
|
+
const tokens = [];
|
|
347
|
+
let i = 0;
|
|
348
|
+
while (i < expr.length) {
|
|
349
|
+
const ch = expr[i];
|
|
350
|
+
if (/\s/.test(ch)) {
|
|
351
|
+
i++;
|
|
352
|
+
continue;
|
|
353
|
+
}
|
|
354
|
+
if (/\d/.test(ch) || ch === "." && /\d/.test(expr[i + 1] ?? "")) {
|
|
355
|
+
let numStr = "";
|
|
356
|
+
let hasDot = false;
|
|
357
|
+
while (i < expr.length) {
|
|
358
|
+
const c = expr[i];
|
|
359
|
+
if (c === ".") {
|
|
360
|
+
if (hasDot)
|
|
361
|
+
break;
|
|
362
|
+
hasDot = true;
|
|
363
|
+
} else if (!/\d/.test(c)) {
|
|
364
|
+
break;
|
|
365
|
+
}
|
|
366
|
+
numStr += c;
|
|
367
|
+
i++;
|
|
368
|
+
}
|
|
369
|
+
const num = parseFloat(numStr);
|
|
370
|
+
if (!Number.isFinite(num)) {
|
|
371
|
+
throw new Error("Invalid number");
|
|
372
|
+
}
|
|
373
|
+
tokens.push({ kind: "NUMBER", value: num });
|
|
374
|
+
continue;
|
|
375
|
+
}
|
|
376
|
+
if (/[a-zA-Z_]/.test(ch)) {
|
|
377
|
+
let id = "";
|
|
378
|
+
while (i < expr.length) {
|
|
379
|
+
const c = expr[i];
|
|
380
|
+
if (!/[a-zA-Z0-9_]/.test(c))
|
|
381
|
+
break;
|
|
382
|
+
id += c;
|
|
383
|
+
i++;
|
|
384
|
+
}
|
|
385
|
+
tokens.push({ kind: "IDENTIFIER", value: id.toLowerCase() });
|
|
386
|
+
continue;
|
|
387
|
+
}
|
|
388
|
+
if (ch === "<" && expr[i + 1] === "=") {
|
|
389
|
+
tokens.push({ kind: "LE", value: "<=" });
|
|
390
|
+
i += 2;
|
|
391
|
+
continue;
|
|
392
|
+
}
|
|
393
|
+
if (ch === ">" && expr[i + 1] === "=") {
|
|
394
|
+
tokens.push({ kind: "GE", value: ">=" });
|
|
395
|
+
i += 2;
|
|
396
|
+
continue;
|
|
397
|
+
}
|
|
398
|
+
if (ch === "!" && expr[i + 1] === "=") {
|
|
399
|
+
tokens.push({ kind: "NE", value: "!=" });
|
|
400
|
+
i += 2;
|
|
401
|
+
continue;
|
|
402
|
+
}
|
|
403
|
+
if (ch === "<" && expr[i + 1] === ">") {
|
|
404
|
+
tokens.push({ kind: "NE", value: "<>" });
|
|
405
|
+
i += 2;
|
|
406
|
+
continue;
|
|
407
|
+
}
|
|
408
|
+
if (ch === "!") {
|
|
409
|
+
tokens.push({ kind: "BANG", value: "!" });
|
|
410
|
+
i++;
|
|
411
|
+
continue;
|
|
412
|
+
}
|
|
413
|
+
switch (ch) {
|
|
414
|
+
case "+":
|
|
415
|
+
tokens.push({ kind: "PLUS", value: "+" });
|
|
416
|
+
break;
|
|
417
|
+
case "-":
|
|
418
|
+
tokens.push({ kind: "MINUS", value: "-" });
|
|
419
|
+
break;
|
|
420
|
+
case "*":
|
|
421
|
+
tokens.push({ kind: "STAR", value: "*" });
|
|
422
|
+
break;
|
|
423
|
+
case "/":
|
|
424
|
+
tokens.push({ kind: "SLASH", value: "/" });
|
|
425
|
+
break;
|
|
426
|
+
case "%":
|
|
427
|
+
tokens.push({ kind: "PERCENT", value: "%" });
|
|
428
|
+
break;
|
|
429
|
+
case "^":
|
|
430
|
+
tokens.push({ kind: "CARET", value: "^" });
|
|
431
|
+
break;
|
|
432
|
+
case "(":
|
|
433
|
+
tokens.push({ kind: "LPAREN", value: "(" });
|
|
434
|
+
break;
|
|
435
|
+
case ")":
|
|
436
|
+
tokens.push({ kind: "RPAREN", value: ")" });
|
|
437
|
+
break;
|
|
438
|
+
case ",":
|
|
439
|
+
tokens.push({ kind: "COMMA", value: "," });
|
|
440
|
+
break;
|
|
441
|
+
case "<":
|
|
442
|
+
tokens.push({ kind: "LT", value: "<" });
|
|
443
|
+
break;
|
|
444
|
+
case ">":
|
|
445
|
+
tokens.push({ kind: "GT", value: ">" });
|
|
446
|
+
break;
|
|
447
|
+
case "=":
|
|
448
|
+
tokens.push({ kind: "EQ", value: "=" });
|
|
449
|
+
break;
|
|
450
|
+
default:
|
|
451
|
+
throw new Error(`Unknown character: ${ch}`);
|
|
452
|
+
}
|
|
453
|
+
i++;
|
|
454
|
+
}
|
|
455
|
+
tokens.push({ kind: "EOF", value: "" });
|
|
456
|
+
return tokens;
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
class ExprParser {
|
|
460
|
+
tokens;
|
|
461
|
+
pos = 0;
|
|
462
|
+
constructor(tokens) {
|
|
463
|
+
this.tokens = tokens;
|
|
464
|
+
}
|
|
465
|
+
parse() {
|
|
466
|
+
const result = this.parseOr();
|
|
467
|
+
if (this.current().kind !== "EOF") {
|
|
468
|
+
throw new Error("too many values in the stack");
|
|
469
|
+
}
|
|
470
|
+
return result;
|
|
471
|
+
}
|
|
472
|
+
current() {
|
|
473
|
+
return this.tokens[this.pos] ?? { kind: "EOF", value: "" };
|
|
474
|
+
}
|
|
475
|
+
advance() {
|
|
476
|
+
const token = this.current();
|
|
477
|
+
this.pos++;
|
|
478
|
+
return token;
|
|
479
|
+
}
|
|
480
|
+
parseOr() {
|
|
481
|
+
let left = this.parseAnd();
|
|
482
|
+
while (this.current().kind === "IDENTIFIER" && this.current().value === "or") {
|
|
483
|
+
this.advance();
|
|
484
|
+
const right = this.parseAnd();
|
|
485
|
+
left = isTruthyNum(left) || isTruthyNum(right) ? 1 : 0;
|
|
486
|
+
}
|
|
487
|
+
return left;
|
|
488
|
+
}
|
|
489
|
+
parseAnd() {
|
|
490
|
+
let left = this.parseNot();
|
|
491
|
+
while (this.current().kind === "IDENTIFIER" && this.current().value === "and") {
|
|
492
|
+
this.advance();
|
|
493
|
+
const right = this.parseNot();
|
|
494
|
+
left = isTruthyNum(left) && isTruthyNum(right) ? 1 : 0;
|
|
495
|
+
}
|
|
496
|
+
return left;
|
|
497
|
+
}
|
|
498
|
+
parseNot() {
|
|
499
|
+
const cur = this.current();
|
|
500
|
+
if (cur.kind === "IDENTIFIER" && cur.value === "not" || cur.kind === "BANG") {
|
|
501
|
+
this.advance();
|
|
502
|
+
const value = this.parseNot();
|
|
503
|
+
return isTruthyNum(value) ? 0 : 1;
|
|
504
|
+
}
|
|
505
|
+
return this.parseComparison();
|
|
506
|
+
}
|
|
507
|
+
parseComparison() {
|
|
508
|
+
let left = this.parseAddition();
|
|
509
|
+
const kind = this.current().kind;
|
|
510
|
+
if (kind === "LT" || kind === "GT" || kind === "LE" || kind === "GE" || kind === "EQ" || kind === "NE") {
|
|
511
|
+
this.advance();
|
|
512
|
+
const right = this.parseAddition();
|
|
513
|
+
switch (kind) {
|
|
514
|
+
case "LT":
|
|
515
|
+
return left < right ? 1 : 0;
|
|
516
|
+
case "GT":
|
|
517
|
+
return left > right ? 1 : 0;
|
|
518
|
+
case "LE":
|
|
519
|
+
return left <= right ? 1 : 0;
|
|
520
|
+
case "GE":
|
|
521
|
+
return left >= right ? 1 : 0;
|
|
522
|
+
case "EQ":
|
|
523
|
+
return left === right ? 1 : 0;
|
|
524
|
+
case "NE":
|
|
525
|
+
return left !== right ? 1 : 0;
|
|
526
|
+
}
|
|
527
|
+
}
|
|
528
|
+
return left;
|
|
529
|
+
}
|
|
530
|
+
parseAddition() {
|
|
531
|
+
let left = this.parseMultiplication();
|
|
532
|
+
while (true) {
|
|
533
|
+
const kind = this.current().kind;
|
|
534
|
+
if (kind === "PLUS") {
|
|
535
|
+
this.advance();
|
|
536
|
+
left = left + this.parseMultiplication();
|
|
537
|
+
} else if (kind === "MINUS") {
|
|
538
|
+
this.advance();
|
|
539
|
+
left = left - this.parseMultiplication();
|
|
540
|
+
} else {
|
|
541
|
+
break;
|
|
542
|
+
}
|
|
543
|
+
}
|
|
544
|
+
return left;
|
|
545
|
+
}
|
|
546
|
+
parseMultiplication() {
|
|
547
|
+
let left = this.parsePower();
|
|
548
|
+
while (true) {
|
|
549
|
+
const kind = this.current().kind;
|
|
550
|
+
if (kind === "STAR") {
|
|
551
|
+
this.advance();
|
|
552
|
+
left = left * this.parsePower();
|
|
553
|
+
} else if (kind === "SLASH") {
|
|
554
|
+
this.advance();
|
|
555
|
+
left = left / this.parsePower();
|
|
556
|
+
} else if (kind === "PERCENT") {
|
|
557
|
+
this.advance();
|
|
558
|
+
left = left % this.parsePower();
|
|
559
|
+
} else {
|
|
560
|
+
break;
|
|
561
|
+
}
|
|
562
|
+
}
|
|
563
|
+
return left;
|
|
564
|
+
}
|
|
565
|
+
parsePower() {
|
|
566
|
+
const left = this.parseUnary();
|
|
567
|
+
if (this.current().kind === "CARET") {
|
|
568
|
+
this.advance();
|
|
569
|
+
const right = this.parsePower();
|
|
570
|
+
return Math.pow(left, right);
|
|
571
|
+
}
|
|
572
|
+
return left;
|
|
573
|
+
}
|
|
574
|
+
parseUnary() {
|
|
575
|
+
const kind = this.current().kind;
|
|
576
|
+
if (kind === "MINUS") {
|
|
577
|
+
this.advance();
|
|
578
|
+
return -this.parseUnary();
|
|
579
|
+
}
|
|
580
|
+
if (kind === "PLUS") {
|
|
581
|
+
this.advance();
|
|
582
|
+
return +this.parseUnary();
|
|
583
|
+
}
|
|
584
|
+
if (kind === "BANG") {
|
|
585
|
+
this.advance();
|
|
586
|
+
const value = this.parseUnary();
|
|
587
|
+
return isTruthyNum(value) ? 0 : 1;
|
|
588
|
+
}
|
|
589
|
+
return this.parsePrimary();
|
|
590
|
+
}
|
|
591
|
+
parsePrimary() {
|
|
592
|
+
const token = this.current();
|
|
593
|
+
if (token.kind === "NUMBER") {
|
|
594
|
+
this.advance();
|
|
595
|
+
return token.value;
|
|
596
|
+
}
|
|
597
|
+
if (token.kind === "LPAREN") {
|
|
598
|
+
this.advance();
|
|
599
|
+
const value = this.parseOr();
|
|
600
|
+
if (this.current().kind !== "RPAREN") {
|
|
601
|
+
throw new Error("Expected )");
|
|
602
|
+
}
|
|
603
|
+
this.advance();
|
|
604
|
+
return value;
|
|
605
|
+
}
|
|
606
|
+
if (token.kind === "IDENTIFIER") {
|
|
607
|
+
const name = token.value;
|
|
608
|
+
this.advance();
|
|
609
|
+
if (this.current().kind === "LPAREN") {
|
|
610
|
+
return this.parseFunctionCall(name);
|
|
611
|
+
}
|
|
612
|
+
if (name === "true")
|
|
613
|
+
return 1;
|
|
614
|
+
if (name === "false")
|
|
615
|
+
return 0;
|
|
616
|
+
throw new Error(`undefined constant "${name}"`);
|
|
617
|
+
}
|
|
618
|
+
throw new Error("Expected expression");
|
|
619
|
+
}
|
|
620
|
+
parseFunctionCall(name) {
|
|
621
|
+
if (this.current().kind !== "LPAREN") {
|
|
622
|
+
throw new Error("Expected (");
|
|
623
|
+
}
|
|
624
|
+
this.advance();
|
|
625
|
+
const args = [];
|
|
626
|
+
if (this.current().kind !== "RPAREN") {
|
|
627
|
+
args.push(this.parseOr());
|
|
628
|
+
while (this.current().kind === "COMMA") {
|
|
629
|
+
this.advance();
|
|
630
|
+
args.push(this.parseOr());
|
|
631
|
+
}
|
|
632
|
+
}
|
|
633
|
+
if (this.current().kind !== "RPAREN") {
|
|
634
|
+
throw new Error("Expected )");
|
|
635
|
+
}
|
|
636
|
+
this.advance();
|
|
637
|
+
return this.callFunction(name, args);
|
|
638
|
+
}
|
|
639
|
+
callFunction(name, args) {
|
|
640
|
+
switch (name) {
|
|
641
|
+
case "abs":
|
|
642
|
+
this.checkArgs(name, args, 1);
|
|
643
|
+
return Math.abs(args[0]);
|
|
644
|
+
case "min":
|
|
645
|
+
this.checkArgsMin(name, args, 1);
|
|
646
|
+
return Math.min(...args);
|
|
647
|
+
case "max":
|
|
648
|
+
this.checkArgsMin(name, args, 1);
|
|
649
|
+
return Math.max(...args);
|
|
650
|
+
case "floor":
|
|
651
|
+
this.checkArgs(name, args, 1);
|
|
652
|
+
return Math.floor(args[0]);
|
|
653
|
+
case "ceil":
|
|
654
|
+
this.checkArgs(name, args, 1);
|
|
655
|
+
return Math.ceil(args[0]);
|
|
656
|
+
case "round":
|
|
657
|
+
this.checkArgs(name, args, 1);
|
|
658
|
+
return Math.round(args[0]);
|
|
659
|
+
case "sqrt":
|
|
660
|
+
this.checkArgs(name, args, 1);
|
|
661
|
+
return Math.sqrt(args[0]);
|
|
662
|
+
case "sin":
|
|
663
|
+
this.checkArgs(name, args, 1);
|
|
664
|
+
return Math.sin(args[0]);
|
|
665
|
+
case "cos":
|
|
666
|
+
this.checkArgs(name, args, 1);
|
|
667
|
+
return Math.cos(args[0]);
|
|
668
|
+
case "tan":
|
|
669
|
+
this.checkArgs(name, args, 1);
|
|
670
|
+
return Math.tan(args[0]);
|
|
671
|
+
case "ln":
|
|
672
|
+
this.checkArgs(name, args, 1);
|
|
673
|
+
return Math.log(args[0]);
|
|
674
|
+
case "log":
|
|
675
|
+
this.checkArgs(name, args, 1);
|
|
676
|
+
return Math.log10(args[0]);
|
|
677
|
+
case "exp":
|
|
678
|
+
this.checkArgs(name, args, 1);
|
|
679
|
+
return Math.exp(args[0]);
|
|
680
|
+
case "pow":
|
|
681
|
+
this.checkArgs(name, args, 2);
|
|
682
|
+
return Math.pow(args[0], args[1]);
|
|
683
|
+
default:
|
|
684
|
+
throw new Error(`undefined function "${name}"`);
|
|
685
|
+
}
|
|
686
|
+
}
|
|
687
|
+
checkArgs(name, args, expected) {
|
|
688
|
+
if (args.length !== expected) {
|
|
689
|
+
throw new Error(`${name}() expects ${expected} argument(s), got ${args.length}`);
|
|
690
|
+
}
|
|
691
|
+
}
|
|
692
|
+
checkArgsMin(name, args, min) {
|
|
693
|
+
if (args.length < min) {
|
|
694
|
+
throw new Error(`${name}() expects at least ${min} argument(s), got ${args.length}`);
|
|
695
|
+
}
|
|
696
|
+
}
|
|
697
|
+
}
|
|
253
698
|
// packages/ast/src/settings.ts
|
|
254
699
|
function createSettings(mode) {
|
|
255
700
|
switch (mode) {
|
package/dist/index.d.cts
CHANGED
|
@@ -64,22 +64,29 @@ declare function createPoint(line: number, column: number, offset: number): Poin
|
|
|
64
64
|
*/
|
|
65
65
|
declare function createPosition(start: Point, end: Point): Position;
|
|
66
66
|
/**
|
|
67
|
-
*
|
|
67
|
+
* Shared CSS value definitions used across parser and renderer.
|
|
68
68
|
*
|
|
69
|
-
*
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
*
|
|
69
|
+
* @module
|
|
70
|
+
*/
|
|
71
|
+
/**
|
|
72
|
+
* All CSS length units (plus percentage) accepted where Wikidot markup
|
|
73
|
+
* takes a size value.
|
|
73
74
|
*
|
|
74
|
-
*
|
|
75
|
-
*
|
|
76
|
-
*
|
|
77
|
-
*
|
|
78
|
-
* // tree.elements[0] → { element: "container", data: { type: "paragraph", ... } }
|
|
79
|
-
* ```
|
|
75
|
+
* This is intentionally a superset of what legacy Wikidot accepts: wdpr
|
|
76
|
+
* extends size validation to modern CSS units (viewport, container-query,
|
|
77
|
+
* and root-relative units) instead of mirroring Wikidot's historical
|
|
78
|
+
* `px|em|%` allowlists. Units are canonicalized to lowercase.
|
|
80
79
|
*
|
|
81
|
-
* @
|
|
80
|
+
* @group CSS
|
|
81
|
+
*/
|
|
82
|
+
declare const CSS_LENGTH_UNITS: readonly ["cqmax", "cqmin", "cqw", "cqh", "cqi", "cqb", "svmin", "svmax", "lvmin", "lvmax", "dvmin", "dvmax", "vmin", "vmax", "svw", "svh", "svi", "svb", "lvw", "lvh", "lvi", "lvb", "dvw", "dvh", "dvi", "dvb", "vw", "vh", "vi", "vb", "rcap", "rem", "rex", "rch", "ric", "rlh", "cap", "em", "ex", "ch", "ic", "lh", "cm", "mm", "in", "pc", "pt", "px", "q", "%"];
|
|
83
|
+
/**
|
|
84
|
+
* A CSS length unit (or percentage) accepted in size values,
|
|
85
|
+
* canonicalized to lowercase.
|
|
86
|
+
*
|
|
87
|
+
* @group CSS
|
|
82
88
|
*/
|
|
89
|
+
type CssLengthUnit = (typeof CSS_LENGTH_UNITS)[number];
|
|
83
90
|
/**
|
|
84
91
|
* Key-value map of HTML attributes.
|
|
85
92
|
* Populated from the Wikidot `_ class="foo" style="color:red"` attribute syntax.
|
|
@@ -488,6 +495,25 @@ type Module = {
|
|
|
488
495
|
} | {
|
|
489
496
|
/** `[[module Rate]]` — page rating widget */
|
|
490
497
|
module: "rate";
|
|
498
|
+
} | {
|
|
499
|
+
/** `[[module TagCloud]]` — weighted cloud of page tags */
|
|
500
|
+
module: "tag-cloud";
|
|
501
|
+
/** Numeric part of the font size for the lightest-weighted tag */
|
|
502
|
+
"min-font-size": number;
|
|
503
|
+
/** Numeric part of the font size for the heaviest-weighted tag */
|
|
504
|
+
"max-font-size": number;
|
|
505
|
+
/** Unit shared by both font sizes (lowercase) */
|
|
506
|
+
"font-size-unit": CssLengthUnit;
|
|
507
|
+
/** RGB components for the lightest-weighted tag */
|
|
508
|
+
"min-color": [number, number, number];
|
|
509
|
+
/** RGB components for the heaviest-weighted tag */
|
|
510
|
+
"max-color": [number, number, number];
|
|
511
|
+
/** Normalized link target prefix, always ending with `/tag/` */
|
|
512
|
+
target: string;
|
|
513
|
+
/** Maximum number of tags to display */
|
|
514
|
+
limit: number;
|
|
515
|
+
/** Category filter, or null for all categories */
|
|
516
|
+
category: string | null;
|
|
491
517
|
} | {
|
|
492
518
|
/** `[[module ListUsers]]` — user listing with template body */
|
|
493
519
|
module: "list-users";
|
|
@@ -1251,6 +1277,51 @@ declare function createSettings(mode: WikitextMode): WikitextSettings;
|
|
|
1251
1277
|
*/
|
|
1252
1278
|
declare const DEFAULT_SETTINGS: WikitextSettings;
|
|
1253
1279
|
/**
|
|
1280
|
+
* Determine whether a string value is truthy for Wikidot's `#if` construct.
|
|
1281
|
+
*
|
|
1282
|
+
* The value is lowercased and trimmed before checking against the set of
|
|
1283
|
+
* known falsy strings (`"false"`, `"null"`, `""`, `"0"`).
|
|
1284
|
+
*
|
|
1285
|
+
* @param value - The condition string to check.
|
|
1286
|
+
* @returns `true` if the value is not in the falsy set.
|
|
1287
|
+
*/
|
|
1288
|
+
declare function isTruthy(value: string): boolean;
|
|
1289
|
+
/**
|
|
1290
|
+
* Result of evaluating a mathematical expression.
|
|
1291
|
+
* Either a successful numeric value or an error message string.
|
|
1292
|
+
*/
|
|
1293
|
+
type ExprResult = {
|
|
1294
|
+
success: true;
|
|
1295
|
+
value: number;
|
|
1296
|
+
} | {
|
|
1297
|
+
success: false;
|
|
1298
|
+
error: string;
|
|
1299
|
+
};
|
|
1300
|
+
/**
|
|
1301
|
+
* Format a numeric expression result for display.
|
|
1302
|
+
*
|
|
1303
|
+
* Uses JavaScript's default `String(n)` so the full precision of the
|
|
1304
|
+
* computed value is preserved (e.g. `1/3` becomes `"0.3333333333333333"`,
|
|
1305
|
+
* matching the `Number` → `String` conversion rather than truncating to
|
|
1306
|
+
* a fixed number of decimals). Used by both the inline renderer and the
|
|
1307
|
+
* opener preprocess so the same expression produces the same string
|
|
1308
|
+
* regardless of where it appears in the source.
|
|
1309
|
+
*/
|
|
1310
|
+
declare function formatExprValue(n: number): string;
|
|
1311
|
+
/**
|
|
1312
|
+
* Evaluate a mathematical expression string and return the result.
|
|
1313
|
+
*
|
|
1314
|
+
* The expression is tokenized, parsed with a recursive descent parser,
|
|
1315
|
+
* and evaluated in a single pass. Errors produce Wikidot-compatible
|
|
1316
|
+
* messages (e.g., `"division by zero"`, `"too many values in the stack"`).
|
|
1317
|
+
*
|
|
1318
|
+
* NaN and Infinity results are treated as division-by-zero errors.
|
|
1319
|
+
*
|
|
1320
|
+
* @param expr - The expression string to evaluate.
|
|
1321
|
+
* @returns A success result with a numeric value, or an error result with a message.
|
|
1322
|
+
*/
|
|
1323
|
+
declare function evaluateExpression(expr: string): ExprResult;
|
|
1324
|
+
/**
|
|
1254
1325
|
* Identifies the source markup dialect.
|
|
1255
1326
|
*
|
|
1256
1327
|
* Currently only `"wikidot"` is supported. Included in {@link SyntaxTree}
|
|
@@ -1259,4 +1330,4 @@ declare const DEFAULT_SETTINGS: WikitextSettings;
|
|
|
1259
1330
|
* @group Core
|
|
1260
1331
|
*/
|
|
1261
1332
|
type Version = "wikidot";
|
|
1262
|
-
export { text, paragraph, listItemSubList, listItemElements, list, link, lineBreak, italics, isStringContainerType, isParagraphSafe, isHeaderType, isContainerTypeParagraphSafe, isAlignType, horizontalRule, heading, createSettings, createPosition, createPoint, container, bold, WikitextSettings, WikitextMode, Version, VariableMap, UserData, TocEntry, TableRow, TableOfContentsData, TableData, TableCell, TabData, SyntaxTree, StringContainerType, STYLE_SLOT_PREFIX, Position, Point, ParseResult, PageRef, Module, MathInlineData, MathData, ListType, ListItem, ListData, LinkType, LinkLocation, LinkLabel, LinkData, IncludeData, ImageSource, ImageData, IframeData, IfTagsData, IfExprData, IfCondData, HtmlData, HeadingLevel, Heading, HeaderType, FootnoteBlockData, FloatAlignment, ExprData, EmbedBlockData, Embed, ElementOf, ElementName, ElementDataMap, ElementData, Element, DiagnosticSeverity, Diagnostic, DefinitionListItem, DateItem, DateData, DEFAULT_SETTINGS, ContainerType, ContainerData, ColorData, CollapsibleData, CodeBlockData, ClearFloat, BibliographyCiteData, BibliographyBlockData, AttributeMap, AnchorTarget, AnchorData, Alignment, AlignType };
|
|
1333
|
+
export { text, paragraph, listItemSubList, listItemElements, list, link, lineBreak, italics, isTruthy, isStringContainerType, isParagraphSafe, isHeaderType, isContainerTypeParagraphSafe, isAlignType, horizontalRule, heading, formatExprValue, evaluateExpression, createSettings, createPosition, createPoint, container, bold, WikitextSettings, WikitextMode, Version, VariableMap, UserData, TocEntry, TableRow, TableOfContentsData, TableData, TableCell, TabData, SyntaxTree, StringContainerType, STYLE_SLOT_PREFIX, Position, Point, ParseResult, PageRef, Module, MathInlineData, MathData, ListType, ListItem, ListData, LinkType, LinkLocation, LinkLabel, LinkData, IncludeData, ImageSource, ImageData, IframeData, IfTagsData, IfExprData, IfCondData, HtmlData, HeadingLevel, Heading, HeaderType, FootnoteBlockData, FloatAlignment, ExprResult, ExprData, EmbedBlockData, Embed, ElementOf, ElementName, ElementDataMap, ElementData, Element, DiagnosticSeverity, Diagnostic, DefinitionListItem, DateItem, DateData, DEFAULT_SETTINGS, CssLengthUnit, ContainerType, ContainerData, ColorData, CollapsibleData, CodeBlockData, ClearFloat, CSS_LENGTH_UNITS, BibliographyCiteData, BibliographyBlockData, AttributeMap, AnchorTarget, AnchorData, Alignment, AlignType };
|