@lucidkiln/core 1.1.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.
- package/CHANGELOG.md +5 -0
- package/dist/{ast-1akLiy-A.d.ts → ast-DDhHuwaY.d.ts} +15 -22
- package/dist/ast-DDhHuwaY.d.ts.map +1 -0
- package/dist/cli.js +2 -2
- package/dist/{environment-DkfrPazl.d.ts → environment-DBvRrOn0.d.ts} +15 -8
- package/dist/environment-DBvRrOn0.d.ts.map +1 -0
- package/dist/{format-CLCViAPn.js → format-Di6-GUtH.js} +4 -4
- package/dist/{format-CLCViAPn.js.map → format-Di6-GUtH.js.map} +1 -1
- package/dist/format.d.ts.map +1 -1
- package/dist/format.js +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js +50 -147
- package/dist/index.js.map +1 -1
- package/dist/node.d.ts +1 -1
- package/dist/{parser-BU5dThuk.js → parser-isboTef0.js} +59 -99
- package/dist/parser-isboTef0.js.map +1 -0
- package/dist/{source-BHcxowQp.js → source-BbikGqIb.js} +25 -97
- package/dist/source-BbikGqIb.js.map +1 -0
- package/dist/syntax.d.ts +1 -1
- package/dist/syntax.js +1 -1
- package/package.json +1 -1
- package/dist/ast-1akLiy-A.d.ts.map +0 -1
- package/dist/environment-DkfrPazl.d.ts.map +0 -1
- package/dist/parser-BU5dThuk.js.map +0 -1
- package/dist/source-BHcxowQp.js.map +0 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { n as contentStart } from "./parser-
|
|
1
|
+
import { n as contentStart } from "./parser-isboTef0.js";
|
|
2
2
|
//#region src/errors.ts
|
|
3
3
|
/** Creates a diagnostic for a span of a source. */
|
|
4
4
|
const createDiagnostic = (source, code, message, span, severity = "error") => ({
|
|
@@ -373,8 +373,6 @@ const variableNames = (scope) => {
|
|
|
373
373
|
/** An empty output buffer. Captures start with one too, since what they capture is printed as a value. */
|
|
374
374
|
const emptyOut = () => ({
|
|
375
375
|
s: "",
|
|
376
|
-
indent: "",
|
|
377
|
-
inline: false,
|
|
378
376
|
ahead: null
|
|
379
377
|
});
|
|
380
378
|
/** The scope a block's body renders in: its own when it may set variables. */
|
|
@@ -537,15 +535,6 @@ var Run = class Run {
|
|
|
537
535
|
};
|
|
538
536
|
//#endregion
|
|
539
537
|
//#region src/runtime/outlets.ts
|
|
540
|
-
/**
|
|
541
|
-
* Stands for the outlet's indentation in added content, which is rendered before the outlet may be reached. The
|
|
542
|
-
* outlet puts its own indentation in place when it closes, so content lines up the same whichever runs first, and a
|
|
543
|
-
* cached section's additions line up wherever they are replayed. Two Unicode noncharacters, meant for uses like
|
|
544
|
-
* this. Indentation can land mid-line, where a tag's line ending was removed, so the marker is replaced wherever it
|
|
545
|
-
* is. Data holding one of the characters on its own is left alone.
|
|
546
|
-
*/
|
|
547
|
-
const OUTLET_INDENT = "";
|
|
548
|
-
const INDENT_MARKERS = /\uFDD0\uFDD1/g;
|
|
549
538
|
/** The additions in a log, in order, with each capture's in its place. See `Capture`. */
|
|
550
539
|
const additionsIn = (log, into = []) => {
|
|
551
540
|
for (const entry of log) if (entry instanceof Capture) {
|
|
@@ -607,10 +596,10 @@ const closedError = (run, span, outlet) => fail(run, span, "outlet-closed", `Out
|
|
|
607
596
|
/** Closes every outlet reached so far, fixing its content. */
|
|
608
597
|
const closeOutlets = (state) => {
|
|
609
598
|
if (state.outlets === null) return;
|
|
610
|
-
for (const [name, mark] of state.outlets) if (mark.content === null) mark.content = contentFor(state, name
|
|
599
|
+
for (const [name, mark] of state.outlets) if (mark.content === null) mark.content = contentFor(state, name);
|
|
611
600
|
};
|
|
612
601
|
/** An outlet's content: what was added to it, in order, without repeats of `once` tags. */
|
|
613
|
-
const contentFor = (state, name
|
|
602
|
+
const contentFor = (state, name) => {
|
|
614
603
|
const seen = /* @__PURE__ */ new Set();
|
|
615
604
|
let content = "";
|
|
616
605
|
for (const addition of additionsIn(state.additions ?? [])) {
|
|
@@ -619,8 +608,7 @@ const contentFor = (state, name, mark) => {
|
|
|
619
608
|
if (seen.has(addition.once)) continue;
|
|
620
609
|
seen.add(addition.once);
|
|
621
610
|
}
|
|
622
|
-
|
|
623
|
-
content += html.replace(INDENT_MARKERS, mark.indent);
|
|
611
|
+
content += addition.html;
|
|
624
612
|
}
|
|
625
613
|
return content;
|
|
626
614
|
};
|
|
@@ -659,20 +647,14 @@ const takeOutput = (state, output) => {
|
|
|
659
647
|
return text;
|
|
660
648
|
};
|
|
661
649
|
const NOTHING = () => {};
|
|
650
|
+
/** Whether parts may start early ahead of a part that waits: the render runs fewer parts ahead than it may. */
|
|
651
|
+
const mayRunAhead = (state) => state.ahead < 64;
|
|
662
652
|
/**
|
|
663
|
-
*
|
|
664
|
-
* part
|
|
665
|
-
*
|
|
666
|
-
* and so does the indentation of what comes after it. Check before starting anything that waits for the part.
|
|
667
|
-
*/
|
|
668
|
-
const mayRunAhead = (state, inline) => state.ahead < 64 && !inline;
|
|
669
|
-
/**
|
|
670
|
-
* Starts `rest` while `pending`, the promise of the part before it, waits, and returns a promise for both. `indent` is
|
|
671
|
-
* the indentation `out` had before the part started, which `rest` writes at. Rejects with the part's error when it
|
|
672
|
-
* fails, or else with the rest's, after both settle, so a failed render has nothing still running. Only call it when
|
|
673
|
-
* `mayRunAhead` allows.
|
|
653
|
+
* Starts `rest` while `pending`, the promise of the part before it, waits, and returns a promise for both. Rejects with
|
|
654
|
+
* the part's error when it fails, or else with the rest's, after both settle, so a failed render has nothing still
|
|
655
|
+
* running. Only call it when `mayRunAhead` allows.
|
|
674
656
|
*/
|
|
675
|
-
const runAhead = (run, out, pending,
|
|
657
|
+
const runAhead = (run, out, pending, rest, span) => {
|
|
676
658
|
const state = run.state;
|
|
677
659
|
state.ahead++;
|
|
678
660
|
const log = additionLog(run);
|
|
@@ -683,8 +665,6 @@ const runAhead = (run, out, pending, indent, rest, span) => {
|
|
|
683
665
|
});
|
|
684
666
|
const ahead = {
|
|
685
667
|
s: "",
|
|
686
|
-
indent,
|
|
687
|
-
inline: false,
|
|
688
668
|
ahead: out.ahead ?? {
|
|
689
669
|
base: out,
|
|
690
670
|
size: 0
|
|
@@ -759,17 +739,15 @@ const runGated = (sequence, index, gate, run, scope, out) => {
|
|
|
759
739
|
*/
|
|
760
740
|
const runSequence = (sequence, index, last, run, scope, out, gate) => {
|
|
761
741
|
const statements = sequence.statements;
|
|
762
|
-
const indent = out.indent;
|
|
763
742
|
for (let i = index; i <= last; i++) {
|
|
764
|
-
const inline = out.inline;
|
|
765
743
|
const result = gate === null ? statements[i](run, scope, out) : runGated(sequence, i, gate, run, scope, out);
|
|
766
744
|
if (result === void 0) continue;
|
|
767
745
|
const plan = sequence.plan(run, gate !== null);
|
|
768
746
|
const after = Math.min(plan.after[i], last);
|
|
769
747
|
const end = Math.min(plan.reach[i], last);
|
|
770
|
-
if (end > after && mayRunAhead(run.state
|
|
748
|
+
if (end > after && mayRunAhead(run.state)) {
|
|
771
749
|
const pending = after > i ? result.then(() => runSequence(sequence, i + 1, after, run, scope, out, gate)) : result;
|
|
772
|
-
const joined = runAhead(run, out, pending,
|
|
750
|
+
const joined = runAhead(run, out, pending, (ahead, aheadOut) => runSequence(sequence, after + 1, end, ahead, scope, aheadOut, gate), plan.spans[i]);
|
|
773
751
|
return end === last ? joined : joined.then(() => runSequence(sequence, end + 1, last, run, scope, out, gate));
|
|
774
752
|
}
|
|
775
753
|
return result.then(() => runSequence(sequence, i + 1, last, run, scope, out, gate));
|
|
@@ -779,24 +757,22 @@ const runSequence = (sequence, index, last, run, scope, out, gate) => {
|
|
|
779
757
|
* Runs passes `from` to `to` of a loop in order, waiting only when one returns a promise. Then the passes after it
|
|
780
758
|
* continue as `passesFrom` runs them. `ahead` is whether the loop's passes may run ahead of each other.
|
|
781
759
|
*/
|
|
782
|
-
const runPasses = (run, out, from, to,
|
|
760
|
+
const runPasses = (run, out, from, to, pass, span, ahead) => {
|
|
783
761
|
for (let index = from; index < to; index++) {
|
|
784
|
-
const inline = out.inline;
|
|
785
762
|
const result = pass(run, out, index);
|
|
786
763
|
if (result === void 0) continue;
|
|
787
|
-
return index + 1 < to ? passesFrom(run, out, result,
|
|
764
|
+
return index + 1 < to ? passesFrom(run, out, result, index + 1, to, pass, span, ahead) : result;
|
|
788
765
|
}
|
|
789
766
|
};
|
|
790
767
|
/**
|
|
791
|
-
* Runs passes `from` to `to` of a loop, which come after `pending`, a pass that waits
|
|
792
|
-
*
|
|
793
|
-
*
|
|
794
|
-
*
|
|
795
|
-
* pass started is done.
|
|
768
|
+
* Runs passes `from` to `to` of a loop, which come after `pending`, a pass that waits. When `ahead`, they start at
|
|
769
|
+
* once: each pass that waits lets the passes after it start in a buffer and capture of their own, and every buffer
|
|
770
|
+
* joins `out` in order once all the passes are done. Otherwise, or when `mayRunAhead` refuses, they run once the pass
|
|
771
|
+
* is done. Rejects with the first error in the loop's order, once every pass started is done.
|
|
796
772
|
*/
|
|
797
|
-
const passesFrom = (run, out, pending,
|
|
773
|
+
const passesFrom = (run, out, pending, from, to, pass, span, ahead) => {
|
|
798
774
|
const state = run.state;
|
|
799
|
-
if (!ahead || !mayRunAhead(state
|
|
775
|
+
if (!ahead || !mayRunAhead(state)) return pending.then(() => runPasses(run, out, from, to, pass, span, ahead));
|
|
800
776
|
const log = additionLog(run);
|
|
801
777
|
const outer = run.capture;
|
|
802
778
|
const section = outer?.section ?? null;
|
|
@@ -862,8 +838,6 @@ const passesFrom = (run, out, pending, inline, from, to, indent, pass, span, ahe
|
|
|
862
838
|
const capture = new Capture(log, section, behind);
|
|
863
839
|
const segment = {
|
|
864
840
|
s: "",
|
|
865
|
-
indent,
|
|
866
|
-
inline: false,
|
|
867
841
|
ahead: group
|
|
868
842
|
};
|
|
869
843
|
const segmentRun = run.within(capture);
|
|
@@ -885,7 +859,7 @@ const passesFrom = (run, out, pending, inline, from, to, indent, pass, span, ahe
|
|
|
885
859
|
if (waiting === void 0) break;
|
|
886
860
|
if (index < to && state.ahead >= 64) {
|
|
887
861
|
const next = index;
|
|
888
|
-
waiting = waiting.then(() => runPasses(segmentRun, segment, next, to,
|
|
862
|
+
waiting = waiting.then(() => runPasses(segmentRun, segment, next, to, pass, span, true));
|
|
889
863
|
index = to;
|
|
890
864
|
}
|
|
891
865
|
watch(waiting, at);
|
|
@@ -1297,55 +1271,10 @@ const checkLength = (run, text) => {
|
|
|
1297
1271
|
*/
|
|
1298
1272
|
const write = (run, out, text, span) => {
|
|
1299
1273
|
out.s += text;
|
|
1300
|
-
if (out.inline && text !== "") out.inline = false;
|
|
1301
1274
|
const state = run.state;
|
|
1302
1275
|
const ahead = out.ahead;
|
|
1303
1276
|
if (out.s.length > state.maxSize || ahead !== null && (ahead.size += text.length) + ahead.base.s.length > state.maxSize) throw fail(run, span, "limit-output", `Render stopped after ${state.maxSize} characters of output`);
|
|
1304
1277
|
};
|
|
1305
|
-
/**
|
|
1306
|
-
* Starts inserting content for an include, component, slot or block. `at` is the tag's `indent` when it stands on a
|
|
1307
|
-
* line of its own, which the content's lines get on top of the current indentation. Without it, the tag shares its
|
|
1308
|
-
* line, so the content's first line carries on from it. Tags at the start of a line, with `indent` empty, need
|
|
1309
|
-
* nothing.
|
|
1310
|
-
*
|
|
1311
|
-
* Callers keep `out.indent` and `out.inline` from before, and pass them to `endPlace` with the render's result. A
|
|
1312
|
-
* render that throws stops, so nothing needs restoring then.
|
|
1313
|
-
*/
|
|
1314
|
-
const startPlace = (out, at) => {
|
|
1315
|
-
if (at === void 0) out.inline = true;
|
|
1316
|
-
else out.indent += at;
|
|
1317
|
-
};
|
|
1318
|
-
/** Ends `startPlace` once `result` settles. */
|
|
1319
|
-
const endPlace = (out, indent, inline, result) => {
|
|
1320
|
-
if (result instanceof Promise) return result.then(() => endPlace(out, indent, inline, void 0));
|
|
1321
|
-
out.indent = indent;
|
|
1322
|
-
if (out.inline) out.inline = inline;
|
|
1323
|
-
};
|
|
1324
|
-
const indentedText = (text, lines) => ({
|
|
1325
|
-
text,
|
|
1326
|
-
lines,
|
|
1327
|
-
indent: "",
|
|
1328
|
-
indented: text
|
|
1329
|
-
});
|
|
1330
|
-
/**
|
|
1331
|
-
* The text with `indent` at the start of each line. `inline` is set when it is the first thing written since content
|
|
1332
|
-
* was inserted mid-line, so a line starting straight away gets no indentation. Remembers the last result, since text
|
|
1333
|
-
* is usually inserted at the same indentation each time.
|
|
1334
|
-
*/
|
|
1335
|
-
const indentText = (entry, indent, inline) => {
|
|
1336
|
-
if (entry.indent !== indent) {
|
|
1337
|
-
const { text, lines } = entry;
|
|
1338
|
-
let result = "";
|
|
1339
|
-
let at = 0;
|
|
1340
|
-
for (const start of lines) {
|
|
1341
|
-
result += text.slice(at, start) + indent;
|
|
1342
|
-
at = start;
|
|
1343
|
-
}
|
|
1344
|
-
entry.indented = result + text.slice(at);
|
|
1345
|
-
entry.indent = indent;
|
|
1346
|
-
}
|
|
1347
|
-
return inline && entry.lines[0] === 0 ? entry.indented.slice(indent.length) : entry.indented;
|
|
1348
|
-
};
|
|
1349
1278
|
/** Records the caller's location on a render error that passes through an include, component or `extends`. */
|
|
1350
1279
|
const markCaller = (run, span, error) => {
|
|
1351
1280
|
if (error instanceof KilnRenderError) {
|
|
@@ -1601,16 +1530,15 @@ const renderBody = (run, scope, out, imports, block, gate) => {
|
|
|
1601
1530
|
const { template, state } = run;
|
|
1602
1531
|
const parent = template.parent;
|
|
1603
1532
|
if (!parent && block !== void 0) return renderOnlyBlock(run, scope, out, block);
|
|
1604
|
-
const { indent, inline } = out;
|
|
1605
1533
|
const top = template.top;
|
|
1606
1534
|
const result = gate === null || top === null ? template.body(run, scope, out) : runSequence(top, 0, top.statements.length - 1, run, scope, out, gate);
|
|
1607
1535
|
if (!parent) return result;
|
|
1608
1536
|
const span = template.parentSpan;
|
|
1609
|
-
if (result !== void 0 && !parent.async && block === void 0 && mayRunAhead(state
|
|
1537
|
+
if (result !== void 0 && !parent.async && block === void 0 && mayRunAhead(state)) {
|
|
1610
1538
|
const effects = template.early?.() ?? null;
|
|
1611
1539
|
if (effects !== null) {
|
|
1612
1540
|
const next = gateFor(result, effects, gate);
|
|
1613
|
-
return runAhead(run, out, result,
|
|
1541
|
+
return runAhead(run, out, result, (ahead, aheadOut) => after(loadTemplate(ahead, parent.ev(ahead, scope), span), (layout) => withCaller(ahead, span, () => renderTemplate(state, layout, scope, aheadOut, run.depth + 1, run.slots, null, run.blocks, ahead, span, void 0, next))), span);
|
|
1614
1542
|
}
|
|
1615
1543
|
}
|
|
1616
1544
|
if (result === void 0 && !parent.async) {
|
|
@@ -2401,6 +2329,6 @@ var Source = class {
|
|
|
2401
2329
|
}
|
|
2402
2330
|
};
|
|
2403
2331
|
//#endregion
|
|
2404
|
-
export {
|
|
2332
|
+
export { compare as $, escapeUrl as $t, consume as A, additionsIn as At, loadTemplate as B, fillScope as Bt, getAttr as C, contentSets as Ct, after as D, passesFrom as Dt, addSlotFlags as E, passesAhead as Et, fail as F, RenderState as Ft, renderTemplate as G, sectionCopy as Gt, locating as H, childScope as Ht, hold as I, Run as It, unhold as J, suggest as Jt, silence as K, sectionScope as Kt, holdData as L, blockScope as Lt, embed as M, closeOutlets as Mt, embedKeyed as N, recordAddition as Nt, all as O, runAhead as Ot, embedScope as P, takeOutput as Pt, MISSING as Q, escapeHtml as Qt, importsFor as R, emptyOut as Rt, toTime as S, atFront as St, readableNames as T, mayRunAhead as Tt, markCaller as U, lookup$1 as Ut, locate as V, startCapture as Vt, passData as W, ownerOf as Wt, write as X, isSafe as Xt, withCaller as Y, Markup as Yt, FORMATTERS as Z, safe as Zt, markupText as _, unwrap as _t, operatorFunction as a, KilnSyntaxError as an, isHashLike as at, toPieces as b, expose as bt, checkDepth as c, mapKeys as ct, functionArgument as d, templateFunctions as dt, escapeWith as en, describeType as et, insertedPiece as f, toNumber as ft, mapContents as g, typeName as gt, listOf as h, truthy as ht, contains as i, KilnRenderError as in, isEmpty as it, consumeAt as j, checkLate as jt, checkLength as k, runSequence as kt, entriesOf as l, matchesType as lt, isHtmlStrategy as m, toStringArgument as mt, builtinFunctions as n, resolveTemplateName as nn, equals as nt, rangeOperator as o, createDiagnostic as on, isPlainObject as ot, integerArgument as p, toStr as pt, step as q, variableNames as qt, builtinTests as r, KilnIssue as rn, hashKeys as rt, Kept as s, issue as sn, literalOptions as st, Source as t, TEMPLATE_EXTENSION as tn, describeValue as tt, fromPieces as u, setOwn as ut, readProperty as v, valueLabel as vt, getMethod as w, isRoot as wt, toPlainData as x, lookup as xt, scanHtml as y, BLOCKED_NAMES as yt, isPromise as z, endCapture as zt };
|
|
2405
2333
|
|
|
2406
|
-
//# sourceMappingURL=source-
|
|
2334
|
+
//# sourceMappingURL=source-BbikGqIb.js.map
|