@rohal12/spindle 0.64.13 → 0.64.14
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/pkg/headless.js
CHANGED
|
@@ -13254,6 +13254,7 @@ var BLOCK_MACROS = new NameSet([
|
|
|
13254
13254
|
"do",
|
|
13255
13255
|
"button",
|
|
13256
13256
|
"link",
|
|
13257
|
+
"dialog",
|
|
13257
13258
|
"listbox",
|
|
13258
13259
|
"cycle",
|
|
13259
13260
|
"switch",
|
|
@@ -3633,6 +3633,7 @@ var BLOCK_MACROS = new NameSet([
|
|
|
3633
3633
|
"do",
|
|
3634
3634
|
"button",
|
|
3635
3635
|
"link",
|
|
3636
|
+
"dialog",
|
|
3636
3637
|
"listbox",
|
|
3637
3638
|
"cycle",
|
|
3638
3639
|
"switch",
|
|
@@ -13558,7 +13559,7 @@ var Bindings = class {
|
|
|
13558
13559
|
innermostVisible(bindings, at) {
|
|
13559
13560
|
const useFunction = this.functionStart(at);
|
|
13560
13561
|
const visible = bindings.filter((b) => b.scope.start <= at && at < b.scope.end && (!b.ordered || b.at < at || this.functionStart(b.at) !== useFunction));
|
|
13561
|
-
const innermost =
|
|
13562
|
+
const innermost = visible.reduce((start, b) => Math.max(start, b.scope.start), -Infinity);
|
|
13562
13563
|
return visible.filter((b) => b.scope.start === innermost);
|
|
13563
13564
|
}
|
|
13564
13565
|
readGroups() {
|
|
@@ -25657,6 +25658,14 @@ async function formatLf(text, options) {
|
|
|
25657
25658
|
}
|
|
25658
25659
|
/** Literal HTML and opaque SVG, whose text can inherit significant whitespace. */
|
|
25659
25660
|
var WHITESPACE_AS_WRITTEN = /<(?:pre|textarea|svg)[\s>]|white-space\s*:/i;
|
|
25661
|
+
/** JavaScript MIME types (including legacy aliases) and module scripts. */
|
|
25662
|
+
var JAVASCRIPT_TYPE = /^(?:module|(?:text|application)\/(?:x-)?(?:java|ecma)script|text\/(?:javascript1\.[0-5]|jscript|livescript))$/i;
|
|
25663
|
+
/** Data scripts have opaque bodies, even inside a larger HTML region. */
|
|
25664
|
+
function isDataScript(token) {
|
|
25665
|
+
if (token.tag.toLowerCase() !== "script") return false;
|
|
25666
|
+
const type = Object.entries(token.attributes).find(([name]) => name.toLowerCase() === "type")?.[1].trim();
|
|
25667
|
+
return !!type && !JAVASCRIPT_TYPE.test(type);
|
|
25668
|
+
}
|
|
25660
25669
|
/** HTML whitespace formatting must not collapse the Markdown in its bodies. */
|
|
25661
25670
|
var HTML_MARKDOWN_BOUNDARIES = /* @__PURE__ */ new Set([
|
|
25662
25671
|
"hardBreakTrailing",
|
|
@@ -25684,13 +25693,13 @@ function hasMarkdownBoundaries(source, isBlock) {
|
|
|
25684
25693
|
/** Preserve whole literal elements, including openers beside nested tags. */
|
|
25685
25694
|
function whitespaceSensitiveLines(source, isBlock) {
|
|
25686
25695
|
const lines = /* @__PURE__ */ new Set();
|
|
25687
|
-
if (!WHITESPACE_AS_WRITTEN.test(source)) return lines;
|
|
25696
|
+
if (!WHITESPACE_AS_WRITTEN.test(source) && !/<script[\s>]/i.test(source)) return lines;
|
|
25688
25697
|
const lineAt = sourceLines(source);
|
|
25689
25698
|
const { nodes } = analyzeMarkup(source, { hooks: { isBlock } });
|
|
25690
25699
|
function visit(nodes) {
|
|
25691
25700
|
for (const node of nodes) {
|
|
25692
25701
|
const { token, body } = node;
|
|
25693
|
-
if (token.type === "html" && ([
|
|
25702
|
+
if (token.type === "html" && (isDataScript(token) || [
|
|
25694
25703
|
"pre",
|
|
25695
25704
|
"textarea",
|
|
25696
25705
|
"svg"
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { isBlockMacro } from '../markup/ast';
|
|
2
2
|
import { analyzeMarkup, tokenizeMarkupTolerant } from '../markup/parse';
|
|
3
3
|
import type { PairedNode } from '../markup/pair';
|
|
4
|
-
import type { MacroToken } from '../markup/tokens';
|
|
4
|
+
import type { HtmlToken, MacroToken } from '../markup/tokens';
|
|
5
5
|
import { segmentRegions } from './segment';
|
|
6
6
|
import { markdownLines } from './markdown-lines';
|
|
7
7
|
import { sourceLines } from './source-lines';
|
|
@@ -379,6 +379,19 @@ async function formatLf(
|
|
|
379
379
|
/** Literal HTML and opaque SVG, whose text can inherit significant whitespace. */
|
|
380
380
|
const WHITESPACE_AS_WRITTEN = /<(?:pre|textarea|svg)[\s>]|white-space\s*:/i;
|
|
381
381
|
|
|
382
|
+
/** JavaScript MIME types (including legacy aliases) and module scripts. */
|
|
383
|
+
const JAVASCRIPT_TYPE =
|
|
384
|
+
/^(?:module|(?:text|application)\/(?:x-)?(?:java|ecma)script|text\/(?:javascript1\.[0-5]|jscript|livescript))$/i;
|
|
385
|
+
|
|
386
|
+
/** Data scripts have opaque bodies, even inside a larger HTML region. */
|
|
387
|
+
function isDataScript(token: HtmlToken): boolean {
|
|
388
|
+
if (token.tag.toLowerCase() !== 'script') return false;
|
|
389
|
+
const type = Object.entries(token.attributes)
|
|
390
|
+
.find(([name]) => name.toLowerCase() === 'type')?.[1]
|
|
391
|
+
.trim();
|
|
392
|
+
return !!type && !JAVASCRIPT_TYPE.test(type);
|
|
393
|
+
}
|
|
394
|
+
|
|
382
395
|
/** HTML whitespace formatting must not collapse the Markdown in its bodies. */
|
|
383
396
|
const HTML_MARKDOWN_BOUNDARIES = new Set([
|
|
384
397
|
'hardBreakTrailing',
|
|
@@ -420,7 +433,8 @@ function whitespaceSensitiveLines(
|
|
|
420
433
|
isBlock: (name: string) => boolean,
|
|
421
434
|
): Set<number> {
|
|
422
435
|
const lines = new Set<number>();
|
|
423
|
-
if (!WHITESPACE_AS_WRITTEN.test(source)
|
|
436
|
+
if (!WHITESPACE_AS_WRITTEN.test(source) && !/<script[\s>]/i.test(source))
|
|
437
|
+
return lines;
|
|
424
438
|
const lineAt = sourceLines(source);
|
|
425
439
|
const { nodes } = analyzeMarkup(source, { hooks: { isBlock } });
|
|
426
440
|
function visit(nodes: PairedNode[]): void {
|
|
@@ -428,7 +442,8 @@ function whitespaceSensitiveLines(
|
|
|
428
442
|
const { token, body } = node;
|
|
429
443
|
if (
|
|
430
444
|
token.type === 'html' &&
|
|
431
|
-
(
|
|
445
|
+
(isDataScript(token) ||
|
|
446
|
+
['pre', 'textarea', 'svg'].includes(token.tag.toLowerCase()) ||
|
|
432
447
|
Object.entries(token.attributes).some(
|
|
433
448
|
([name, value]) =>
|
|
434
449
|
name.toLowerCase() === 'style' && /white-space\s*:/i.test(value),
|
package/src/js-bindings.ts
CHANGED
|
@@ -152,7 +152,10 @@ export class Bindings {
|
|
|
152
152
|
at < b.scope.end &&
|
|
153
153
|
(!b.ordered || b.at < at || this.functionStart(b.at) !== useFunction),
|
|
154
154
|
);
|
|
155
|
-
const innermost =
|
|
155
|
+
const innermost = visible.reduce(
|
|
156
|
+
(start, b) => Math.max(start, b.scope.start),
|
|
157
|
+
-Infinity,
|
|
158
|
+
);
|
|
156
159
|
return visible.filter((b) => b.scope.start === innermost);
|
|
157
160
|
}
|
|
158
161
|
|
package/src/markup/ast.ts
CHANGED
|
@@ -365,8 +365,16 @@ function spansOf(text: string, reading: Reading): StyledSpan[] {
|
|
|
365
365
|
const canvas = new Canvas(text.length);
|
|
366
366
|
const comment = openComment(tokens);
|
|
367
367
|
if (comment >= 0) canvas.paint(comment, text.length, 'comment');
|
|
368
|
-
|
|
369
|
-
|
|
368
|
+
const starts = unclosedStarts(text, reading);
|
|
369
|
+
// Later suffix paints cover earlier ones. Paint only their visible parts,
|
|
370
|
+
// retaining each paint's span boundary without repeatedly filling the tail.
|
|
371
|
+
let end = text.length;
|
|
372
|
+
for (let i = starts.length - 1; i >= 0; i--) {
|
|
373
|
+
const start = starts[i]!;
|
|
374
|
+
if (start < end) {
|
|
375
|
+
canvas.paint(start, end, 'error');
|
|
376
|
+
end = start;
|
|
377
|
+
}
|
|
370
378
|
}
|
|
371
379
|
for (const error of errors) {
|
|
372
380
|
if (!isUnclosed(error)) {
|
|
@@ -423,7 +431,9 @@ function openStartOf(text: string, reading: Reading): number {
|
|
|
423
431
|
openDo(tokens)?.start ?? -1,
|
|
424
432
|
openTag(text, tokens),
|
|
425
433
|
].filter((start) => start >= 0);
|
|
426
|
-
return starts.length > 0
|
|
434
|
+
return starts.length > 0
|
|
435
|
+
? starts.reduce((first, start) => Math.min(first, start), Infinity)
|
|
436
|
+
: -1;
|
|
427
437
|
}
|
|
428
438
|
|
|
429
439
|
/**
|