bestax-migrate 2.32.0 → 2.32.1
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/sources/_shared/html/parse.d.ts +10 -0
- package/dist/sources/_shared/html/parse.d.ts.map +1 -1
- package/dist/sources/_shared/html/parse.js +13 -1
- package/dist/sources/bulma-classes/html-assets.d.ts +8 -1
- package/dist/sources/bulma-classes/html-assets.d.ts.map +1 -1
- package/dist/sources/bulma-classes/html-assets.js +30 -5
- package/dist/sources/bulma-classes/html-extensions.d.ts +69 -0
- package/dist/sources/bulma-classes/html-extensions.d.ts.map +1 -0
- package/dist/sources/bulma-classes/html-extensions.js +146 -0
- package/dist/sources/bulma-classes/html-rules.d.ts +5 -0
- package/dist/sources/bulma-classes/html-rules.d.ts.map +1 -1
- package/dist/sources/bulma-classes/html-rules.js +6 -0
- package/dist/sources/bulma-classes/html.d.ts.map +1 -1
- package/dist/sources/bulma-classes/html.js +106 -14
- package/package.json +2 -2
|
@@ -59,6 +59,12 @@ export interface ParsedHtml {
|
|
|
59
59
|
*/
|
|
60
60
|
outsideComments: CommentNode[];
|
|
61
61
|
errors: HtmlParseError[];
|
|
62
|
+
/**
|
|
63
|
+
* Whether a browser reads the document in quirks mode (no doctype, or an
|
|
64
|
+
* old one), where class and id selectors ignore ASCII case. A fragment is
|
|
65
|
+
* read as in no-quirks mode.
|
|
66
|
+
*/
|
|
67
|
+
quirks: boolean;
|
|
62
68
|
}
|
|
63
69
|
/** Whether parse5 should read this source as a whole document. */
|
|
64
70
|
export declare function isDocument(source: string): boolean;
|
|
@@ -67,5 +73,9 @@ export declare function isText(node: Node): node is TextNode;
|
|
|
67
73
|
export declare function isComment(node: Node): node is CommentNode;
|
|
68
74
|
/** An element's children, or a `<template>`'s content, which holds them. */
|
|
69
75
|
export declare function childrenOf(node: ParentNode): ChildNode[];
|
|
76
|
+
/** An attribute's value as written, by its unprefixed name. */
|
|
77
|
+
export declare function attributeOf(element: Element, name: string): string | undefined;
|
|
78
|
+
/** An element's classes, split on HTML's whitespace. */
|
|
79
|
+
export declare function classesOf(element: Element): string[];
|
|
70
80
|
export declare function parseHtml(source: string): ParsedHtml;
|
|
71
81
|
//# sourceMappingURL=parse.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parse.d.ts","sourceRoot":"","sources":["../../../../src/sources/_shared/html/parse.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,
|
|
1
|
+
{"version":3,"file":"parse.d.ts","sourceRoot":"","sources":["../../../../src/sources/_shared/html/parse.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EAIL,KAAK,qBAAqB,EAE1B,KAAK,KAAK,EACX,MAAM,QAAQ,CAAC;AAEhB,MAAM,MAAM,IAAI,GAAG,qBAAqB,CAAC,MAAM,CAAC,CAAC;AACjD,MAAM,MAAM,UAAU,GAAG,qBAAqB,CAAC,YAAY,CAAC,CAAC;AAC7D,MAAM,MAAM,SAAS,GAAG,qBAAqB,CAAC,WAAW,CAAC,CAAC;AAC3D,MAAM,MAAM,OAAO,GAAG,qBAAqB,CAAC,SAAS,CAAC,CAAC;AACvD,MAAM,MAAM,QAAQ,GAAG,qBAAqB,CAAC,UAAU,CAAC,CAAC;AACzD,MAAM,MAAM,QAAQ,GAAG,qBAAqB,CAAC,UAAU,CAAC,CAAC;AACzD,MAAM,MAAM,WAAW,GAAG,qBAAqB,CAAC,aAAa,CAAC,CAAC;AAC/D,MAAM,MAAM,SAAS,GAAG,KAAK,CAAC,SAAS,CAAC;AAExC,MAAM,WAAW,cAAc;IAC7B,yEAAyE;IACzE,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,EAAE,MAAM,CAAC;IACZ;;;;OAIG;IACH,SAAS,CAAC,EAAE,kBAAkB,CAAC;CAChC;AAED;;;;GAIG;AACH,MAAM,WAAW,kBAAkB;IACjC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the page.
|
|
13
13
|
*/
|
|
14
|
-
import { parse, parseFragment, } from 'parse5';
|
|
14
|
+
import { html as spec, parse, parseFragment, } from 'parse5';
|
|
15
15
|
/**
|
|
16
16
|
* The tags that make HTML a document rather than a partial, wherever they
|
|
17
17
|
* sit outside a comment. `<head` is not `<header`.
|
|
@@ -36,6 +36,16 @@ export function childrenOf(node) {
|
|
|
36
36
|
? node.content.childNodes
|
|
37
37
|
: node.childNodes;
|
|
38
38
|
}
|
|
39
|
+
/** An attribute's value as written, by its unprefixed name. */
|
|
40
|
+
export function attributeOf(element, name) {
|
|
41
|
+
return element.attrs.find(attr => attr.name === name && !attr.prefix)?.value;
|
|
42
|
+
}
|
|
43
|
+
/** An element's classes, split on HTML's whitespace. */
|
|
44
|
+
export function classesOf(element) {
|
|
45
|
+
return (attributeOf(element, 'class') ?? '')
|
|
46
|
+
.split(/[ \t\n\f\r]+/)
|
|
47
|
+
.filter(Boolean);
|
|
48
|
+
}
|
|
39
49
|
function find(nodes, tag) {
|
|
40
50
|
return nodes.find((node) => isElement(node) && node.tagName === tag);
|
|
41
51
|
}
|
|
@@ -130,6 +140,7 @@ export function parseHtml(source) {
|
|
|
130
140
|
bodyAttributes: [],
|
|
131
141
|
outsideComments: [],
|
|
132
142
|
errors,
|
|
143
|
+
quirks: false,
|
|
133
144
|
};
|
|
134
145
|
}
|
|
135
146
|
const document = parse(source, options);
|
|
@@ -151,5 +162,6 @@ export function parseHtml(source) {
|
|
|
151
162
|
bodyAttributes: body?.attrs ?? [],
|
|
152
163
|
outsideComments,
|
|
153
164
|
errors,
|
|
165
|
+
quirks: document.mode === spec.DOCUMENT_MODE.QUIRKS,
|
|
154
166
|
};
|
|
155
167
|
}
|
|
@@ -75,7 +75,14 @@ export declare function fontAwesomeMessage(asset: Extract<Asset, {
|
|
|
75
75
|
* name alone), with the component that does what the extension did.
|
|
76
76
|
*/
|
|
77
77
|
export declare const EXTENSION_COMPONENTS: Readonly<Record<string, string>>;
|
|
78
|
-
|
|
78
|
+
/** An extension's package without its scope, in lower case (`bulma-tooltip`). */
|
|
79
|
+
export declare function extensionPackage(name: string): string;
|
|
80
|
+
/**
|
|
81
|
+
* What a page's link to an extension leaves to do. `covered`: the page has
|
|
82
|
+
* images with bulma-carousel's `is-covered`, which its stylesheet crops only
|
|
83
|
+
* inside its own slides, so keeping the extension doesn't keep them cropped.
|
|
84
|
+
*/
|
|
85
|
+
export declare function extensionMessage(name: string, quoted: string[], loads: ReadonlySet<Loads>, css: CssMode, covered?: boolean): string;
|
|
79
86
|
export declare function jqueryMessage(quoted: string): string;
|
|
80
87
|
export declare function webfontMessage(asset: Extract<Asset, {
|
|
81
88
|
kind: 'webfont';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"html-assets.d.ts","sourceRoot":"","sources":["../../../src/sources/bulma-classes/html-assets.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAG9C,MAAM,MAAM,KAAK,GAAG,YAAY,GAAG,QAAQ,CAAC;AAE5C,MAAM,MAAM,KAAK;AACf,iEAAiE;AAC/D;IAAE,IAAI,EAAE,OAAO,CAAC;IAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAAA;CAAE,GAC/D;IAAE,IAAI,EAAE,cAAc,CAAC;IAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IAAC,GAAG,EAAE,OAAO,CAAA;CAAE;AAC9D,sEAAsE;GACpE;IAAE,IAAI,EAAE,iBAAiB,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GACzC;IAAE,IAAI,EAAE,QAAQ,CAAA;CAAE,GAClB;IACE,IAAI,EAAE,SAAS,CAAC;IAChB,KAAK,EAAE,gBAAgB,GAAG,kBAAkB,GAAG,IAAI,CAAC;CACrD,GACD;IAAE,IAAI,EAAE,YAAY,CAAA;CAAE,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AAC;AAEvD;;;;GAIG;AACH,MAAM,WAAW,cAAc;IAC7B,4EAA4E;IAC5E,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,oCAAoC;IACpC,OAAO,EAAE,MAAM,CAAC;IAChB,iFAAiF;IACjF,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;CACzB;AAED,wBAAgB,iBAAiB,CAC/B,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,KAAK,EACZ,MAAM,EAAE,MAAM,EACd,IAAI,CAAC,EAAE,cAAc,GACpB,MAAM,CAeR;AAED,wBAAgB,aAAa,CAC3B,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,KAAK,EACZ,MAAM,EAAE,MAAM,GACb,MAAM,CAQR"}
|
|
@@ -30,7 +30,20 @@ const FONT_AWESOME_MAJOR = [
|
|
|
30
30
|
];
|
|
31
31
|
const FONT_AWESOME_KIT = /(?:^|\/\/)kit\.fontawesome\.com\//i;
|
|
32
32
|
/** A package whose name starts `bulma-`, as a path segment or a file. */
|
|
33
|
-
const EXTENSION = /(?:^|[/\\])((?:@creativebulma\/)?bulma-[a-z\d]+(?:-[a-z\d]+)*)(?=@|[/\\]|(?:\.min)?\.(?:css|js)$)/
|
|
33
|
+
const EXTENSION = /(?:^|[/\\])((?:@creativebulma\/)?bulma-[a-z\d]+(?:-[a-z\d]+)*)(?=@|[/\\]|(?:\.min)?\.(?:css|js)$)/gi;
|
|
34
|
+
/**
|
|
35
|
+
* The extension a URL's path loads: the first package it names, but for a
|
|
36
|
+
* file of one extension inside the bulma-extensions bundle's package
|
|
37
|
+
* (`bulma-extensions@6.2.7/bulma-carousel/dist/…`), which is that one's own
|
|
38
|
+
* file, not the bundle's combined stylesheet or script.
|
|
39
|
+
*/
|
|
40
|
+
function extensionOf(urlPath) {
|
|
41
|
+
const [first, ...rest] = [...urlPath.matchAll(EXTENSION)].map(match => match[1]);
|
|
42
|
+
if (first === undefined || extensionPackage(first) !== 'bulma-extensions') {
|
|
43
|
+
return first;
|
|
44
|
+
}
|
|
45
|
+
return (rest.find(name => extensionPackage(name) !== 'bulma-extensions') ?? first);
|
|
46
|
+
}
|
|
34
47
|
/** jQuery itself, not a plugin: `jquery-3.7.1.min.js`, `jquery@3`. */
|
|
35
48
|
const JQUERY = /(?:^|[/\\])jquery(?:-\d+(?:\.\d+)*)?(?:\.slim)?(?:\.min)?\.js$|(?:^|\/)jquery@[\d.]+$/i;
|
|
36
49
|
/** Hosts that serve a web font's stylesheet. */
|
|
@@ -61,7 +74,7 @@ export function classifyAsset(url, loads) {
|
|
|
61
74
|
kit: FONT_AWESOME_KIT.test(url.trim()),
|
|
62
75
|
};
|
|
63
76
|
}
|
|
64
|
-
const extension =
|
|
77
|
+
const extension = extensionOf(urlPath);
|
|
65
78
|
if (extension)
|
|
66
79
|
return { kind: 'bulma-extension', name: extension };
|
|
67
80
|
if (loads === 'script') {
|
|
@@ -194,9 +207,18 @@ export const EXTENSION_COMPONENTS = {
|
|
|
194
207
|
'bulma-toast': '`Toast` (`toast.show()` from code, with a `ToastContainer` rendered once)',
|
|
195
208
|
'bulma-tooltip': '`Tooltip`',
|
|
196
209
|
};
|
|
197
|
-
|
|
210
|
+
/** An extension's package without its scope, in lower case (`bulma-tooltip`). */
|
|
211
|
+
export function extensionPackage(name) {
|
|
212
|
+
return name.replace(/^@[^/]+\//, '').toLowerCase();
|
|
213
|
+
}
|
|
214
|
+
/**
|
|
215
|
+
* What a page's link to an extension leaves to do. `covered`: the page has
|
|
216
|
+
* images with bulma-carousel's `is-covered`, which its stylesheet crops only
|
|
217
|
+
* inside its own slides, so keeping the extension doesn't keep them cropped.
|
|
218
|
+
*/
|
|
219
|
+
export function extensionMessage(name, quoted, loads, css, covered = false) {
|
|
198
220
|
const from = `from ${quoted.map(url => `\`${url}\``).join(' and ')}`;
|
|
199
|
-
const bare = name
|
|
221
|
+
const bare = extensionPackage(name);
|
|
200
222
|
if (bare === 'bulma-social') {
|
|
201
223
|
return `the page loads bulma-social, a Bulma extension for brand-colored buttons, ${from}, and bestax has no component for it: keep loading it once for the app (\`bulma-social\` from npm, imported from its entry, or the \`<link>\` in its index.html), since its classes (\`is-twitter\`, \`is-github\` and the rest) style Bulma's \`.button\`, which bestax's \`Button\` renders, so they go on \`Button\` through \`className\``;
|
|
202
224
|
}
|
|
@@ -205,7 +227,10 @@ export function extensionMessage(name, quoted, loads, css) {
|
|
|
205
227
|
}
|
|
206
228
|
const component = EXTENSION_COMPONENTS[bare];
|
|
207
229
|
if (component) {
|
|
208
|
-
|
|
230
|
+
const crops = covered && bare === 'bulma-carousel'
|
|
231
|
+
? "; the page's `is-covered` images are cropped by its stylesheet only inside its own slides, which `Carousel` doesn't render, so keeping it doesn't keep them cropped: give them the rule the `html-extension:is-covered` TODO has"
|
|
232
|
+
: '';
|
|
233
|
+
return `the page loads ${name}, a Bulma extension, ${from}, and bestax has a component for what it does: ${component}, whose styles ship in bestax's \`extras.css\` and \`bestax.css\`; render that in place of the extension's markup${loads.has('script') ? ' and script' : ''}, and stop loading the extension once nothing the app keeps uses its classes${crops}`;
|
|
209
234
|
}
|
|
210
235
|
return `the page loads ${name}, a Bulma extension, ${from}, and a component doesn't: keep loading it once for the app (from npm, imported from its entry, or a \`<link>\` in its index.html) while the page's markup uses its classes, which go on bestax's components through \`className\`${css === 'keep' ? '' : ', and check it works with Bulma 1, which an extension can predate'}`;
|
|
211
236
|
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A Bulma extension's own markup on a page, which no component converts:
|
|
3
|
+
* the elements bulma-carousel's script makes carousels of, and its
|
|
4
|
+
* `is-covered` class. `html.ts` notes each under `html-extension:<name>`
|
|
5
|
+
* (`EXTENSION_MARKUP` in `html-rules.ts`), beside the `html-asset` note for
|
|
6
|
+
* the extension and the `html-script:carousel` note for its script.
|
|
7
|
+
*
|
|
8
|
+
* Pure. A script is read, never run, so an element is found only through a
|
|
9
|
+
* selector the script writes out as a string, and only in the forms a page
|
|
10
|
+
* names its carousel by: a tag, ids and classes, and a list of those. The
|
|
11
|
+
* page's DOM is searched the way `querySelectorAll` does it, which is what
|
|
12
|
+
* `bulmaCarousel.attach` calls: every element a selector matches becomes a
|
|
13
|
+
* carousel, an id the page repeats included.
|
|
14
|
+
*/
|
|
15
|
+
import { type Element, type ParentNode } from '../_shared/html/parse.js';
|
|
16
|
+
/** The selectors a script attaches bulma-carousel to, once each, in order. */
|
|
17
|
+
export declare function carouselSelectors(code: string): string[];
|
|
18
|
+
interface Compound {
|
|
19
|
+
/** Null for any tag. */
|
|
20
|
+
tag: string | null;
|
|
21
|
+
ids: string[];
|
|
22
|
+
classes: string[];
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* A selector list the codemod can match, or null for any other selector
|
|
26
|
+
* (a combinator, an attribute, a pseudo-class), whose matches it can't know.
|
|
27
|
+
*/
|
|
28
|
+
export declare function readSelector(selector: string): Compound[] | null;
|
|
29
|
+
/**
|
|
30
|
+
* Every element in the content a selector matches, in the page's order, as
|
|
31
|
+
* `querySelectorAll` finds them once the page's scripts run, or null for a
|
|
32
|
+
* selector `readSelector` can't read. A `<template>`'s content isn't in the
|
|
33
|
+
* document (parse5 keeps it apart from its children), and with scripts on a
|
|
34
|
+
* `<noscript>` holds text, so neither is searched.
|
|
35
|
+
*/
|
|
36
|
+
export declare function selectAll(root: ParentNode, selector: string, quirks: boolean): Element[] | null;
|
|
37
|
+
/** The class bulma-carousel's markup gives a carousel, and bestax `Carousel`'s. */
|
|
38
|
+
export declare const CAROUSEL_CLASS = "carousel";
|
|
39
|
+
/** bulma-carousel's class for an image cropped to its frame. */
|
|
40
|
+
export declare const COVERED_CLASS = "is-covered";
|
|
41
|
+
/** What bulma-carousel's stylesheet styles `is-covered` on: an `.image`. */
|
|
42
|
+
export declare const COVERED_SELECTOR = ".image.is-covered";
|
|
43
|
+
export interface DrivenFacts {
|
|
44
|
+
/** The selector, as the script writes it. */
|
|
45
|
+
selector: string;
|
|
46
|
+
/** The script, as the TODO names it (`the page's script \`js/app.js\``). */
|
|
47
|
+
script: string;
|
|
48
|
+
/** How many elements the selector matches. */
|
|
49
|
+
count: number;
|
|
50
|
+
/** The id they all have, when several do. */
|
|
51
|
+
sharedId?: string;
|
|
52
|
+
/** Whether one of them has the `carousel` class. */
|
|
53
|
+
carouselClass: boolean;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* The elements a page's script attaches bulma-carousel to: each one a
|
|
57
|
+
* carousel, whose children become its slides, and none of it run by the
|
|
58
|
+
* module.
|
|
59
|
+
*/
|
|
60
|
+
export declare function drivenMessage(facts: DrivenFacts): string;
|
|
61
|
+
/**
|
|
62
|
+
* An element with the `carousel` class on a page that uses bulma-carousel,
|
|
63
|
+
* where no selector the codemod read reaches it.
|
|
64
|
+
*/
|
|
65
|
+
export declare function carouselClassMessage(): string;
|
|
66
|
+
/** An `.image` with bulma-carousel's `is-covered`. */
|
|
67
|
+
export declare function coveredMessage(): string;
|
|
68
|
+
export {};
|
|
69
|
+
//# sourceMappingURL=html-extensions.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"html-extensions.d.ts","sourceRoot":"","sources":["../../../src/sources/bulma-classes/html-extensions.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,EAIL,KAAK,OAAO,EACZ,KAAK,UAAU,EAChB,MAAM,0BAA0B,CAAC;AAclC,8EAA8E;AAC9E,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,CAKxD;AAUD,UAAU,QAAQ;IAChB,wBAAwB;IACxB,GAAG,EAAE,MAAM,GAAG,IAAI,CAAC;IACnB,GAAG,EAAE,MAAM,EAAE,CAAC;IACd,OAAO,EAAE,MAAM,EAAE,CAAC;CACnB;AAED;;;GAGG;AACH,wBAAgB,YAAY,CAAC,QAAQ,EAAE,MAAM,GAAG,QAAQ,EAAE,GAAG,IAAI,CAehE;AA4BD;;;;;;GAMG;AACH,wBAAgB,SAAS,CACvB,IAAI,EAAE,UAAU,EAChB,QAAQ,EAAE,MAAM,EAChB,MAAM,EAAE,OAAO,GACd,OAAO,EAAE,GAAG,IAAI,CAelB;AAID,mFAAmF;AACnF,eAAO,MAAM,cAAc,aAAa,CAAC;AAEzC,gEAAgE;AAChE,eAAO,MAAM,aAAa,eAAe,CAAC;AAE1C,4EAA4E;AAC5E,eAAO,MAAM,gBAAgB,sBAA4B,CAAC;AAW1D,MAAM,WAAW,WAAW;IAC1B,6CAA6C;IAC7C,QAAQ,EAAE,MAAM,CAAC;IACjB,4EAA4E;IAC5E,MAAM,EAAE,MAAM,CAAC;IACf,8CAA8C;IAC9C,KAAK,EAAE,MAAM,CAAC;IACd,6CAA6C;IAC7C,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,oDAAoD;IACpD,aAAa,EAAE,OAAO,CAAC;CACxB;AAED;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,WAAW,GAAG,MAAM,CAkBxD;AAED;;;GAGG;AACH,wBAAgB,oBAAoB,IAAI,MAAM,CAE7C;AAED,sDAAsD;AACtD,wBAAgB,cAAc,IAAI,MAAM,CAEvC"}
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A Bulma extension's own markup on a page, which no component converts:
|
|
3
|
+
* the elements bulma-carousel's script makes carousels of, and its
|
|
4
|
+
* `is-covered` class. `html.ts` notes each under `html-extension:<name>`
|
|
5
|
+
* (`EXTENSION_MARKUP` in `html-rules.ts`), beside the `html-asset` note for
|
|
6
|
+
* the extension and the `html-script:carousel` note for its script.
|
|
7
|
+
*
|
|
8
|
+
* Pure. A script is read, never run, so an element is found only through a
|
|
9
|
+
* selector the script writes out as a string, and only in the forms a page
|
|
10
|
+
* names its carousel by: a tag, ids and classes, and a list of those. The
|
|
11
|
+
* page's DOM is searched the way `querySelectorAll` does it, which is what
|
|
12
|
+
* `bulmaCarousel.attach` calls: every element a selector matches becomes a
|
|
13
|
+
* carousel, an id the page repeats included.
|
|
14
|
+
*/
|
|
15
|
+
import { attributeOf, classesOf, isElement, } from '../_shared/html/parse.js';
|
|
16
|
+
const HTML_NS = 'http://www.w3.org/1999/xhtml';
|
|
17
|
+
// ---- What the page's scripts attach bulma-carousel to ------------------------
|
|
18
|
+
/**
|
|
19
|
+
* `bulmaCarousel.attach(` with its selector written as a string, the whole
|
|
20
|
+
* argument, without an escape or a substitution, which would make it
|
|
21
|
+
* something else to read.
|
|
22
|
+
*/
|
|
23
|
+
const ATTACH = /\bbulmaCarousel\s*\.\s*attach\s*\(\s*(?:'([^'\\\n]*)'|"([^"\\\n]*)"|`([^`\\$]*)`)\s*[,)]/g;
|
|
24
|
+
/** The selectors a script attaches bulma-carousel to, once each, in order. */
|
|
25
|
+
export function carouselSelectors(code) {
|
|
26
|
+
const selectors = [...code.matchAll(ATTACH)].map(match => (match[1] ?? match[2] ?? match[3]).trim());
|
|
27
|
+
return [...new Set(selectors.filter(Boolean))];
|
|
28
|
+
}
|
|
29
|
+
// ---- Matching a selector -----------------------------------------------------
|
|
30
|
+
/** A CSS identifier, as a tag, an id or a class writes it. */
|
|
31
|
+
const IDENT = String.raw `(?:--|-?[_a-zA-Z\u0080-\uffff])[-\w\u0080-\uffff]*`;
|
|
32
|
+
/** A tag (or `*`), then ids and classes, with nothing between them. */
|
|
33
|
+
const COMPOUND = new RegExp(String.raw `^(\*|${IDENT})?((?:[#.]${IDENT})*)$`);
|
|
34
|
+
/**
|
|
35
|
+
* A selector list the codemod can match, or null for any other selector
|
|
36
|
+
* (a combinator, an attribute, a pseudo-class), whose matches it can't know.
|
|
37
|
+
*/
|
|
38
|
+
export function readSelector(selector) {
|
|
39
|
+
const compounds = [];
|
|
40
|
+
for (const part of selector.split(',').map(each => each.trim())) {
|
|
41
|
+
const match = part === '' ? null : COMPOUND.exec(part);
|
|
42
|
+
if (!match)
|
|
43
|
+
return null;
|
|
44
|
+
const simple = match[2].match(/[#.][^#.]+/g) ?? [];
|
|
45
|
+
compounds.push({
|
|
46
|
+
tag: match[1] === undefined || match[1] === '*' ? null : match[1],
|
|
47
|
+
ids: simple.filter(each => each[0] === '#').map(each => each.slice(1)),
|
|
48
|
+
classes: simple
|
|
49
|
+
.filter(each => each[0] === '.')
|
|
50
|
+
.map(each => each.slice(1)),
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
return compounds;
|
|
54
|
+
}
|
|
55
|
+
/** ASCII letters in lower case, and nothing else changed. */
|
|
56
|
+
function asciiLower(text) {
|
|
57
|
+
return text.replace(/[A-Z]/g, letter => letter.toLowerCase());
|
|
58
|
+
}
|
|
59
|
+
function matches(element, compound, quirks) {
|
|
60
|
+
if (compound.tag !== null) {
|
|
61
|
+
// An HTML element's tag matches in any case; a foreign one's as written.
|
|
62
|
+
const html = element.namespaceURI === HTML_NS;
|
|
63
|
+
const tag = html ? asciiLower(compound.tag) : compound.tag;
|
|
64
|
+
if (element.tagName !== tag)
|
|
65
|
+
return false;
|
|
66
|
+
}
|
|
67
|
+
// Quirks mode matches ids and classes in any ASCII case.
|
|
68
|
+
const fold = quirks ? asciiLower : (text) => text;
|
|
69
|
+
const id = attributeOf(element, 'id');
|
|
70
|
+
if (compound.ids.some(each => id === undefined || fold(id) !== fold(each))) {
|
|
71
|
+
return false;
|
|
72
|
+
}
|
|
73
|
+
const classes = classesOf(element).map(fold);
|
|
74
|
+
return compound.classes.every(each => classes.includes(fold(each)));
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Every element in the content a selector matches, in the page's order, as
|
|
78
|
+
* `querySelectorAll` finds them once the page's scripts run, or null for a
|
|
79
|
+
* selector `readSelector` can't read. A `<template>`'s content isn't in the
|
|
80
|
+
* document (parse5 keeps it apart from its children), and with scripts on a
|
|
81
|
+
* `<noscript>` holds text, so neither is searched.
|
|
82
|
+
*/
|
|
83
|
+
export function selectAll(root, selector, quirks) {
|
|
84
|
+
const compounds = readSelector(selector);
|
|
85
|
+
if (!compounds)
|
|
86
|
+
return null;
|
|
87
|
+
const found = [];
|
|
88
|
+
const visit = (parent) => {
|
|
89
|
+
for (const child of parent.childNodes) {
|
|
90
|
+
if (!isElement(child))
|
|
91
|
+
continue;
|
|
92
|
+
if (compounds.some(compound => matches(child, compound, quirks))) {
|
|
93
|
+
found.push(child);
|
|
94
|
+
}
|
|
95
|
+
if (child.tagName !== 'noscript')
|
|
96
|
+
visit(child);
|
|
97
|
+
}
|
|
98
|
+
};
|
|
99
|
+
visit(root);
|
|
100
|
+
return found;
|
|
101
|
+
}
|
|
102
|
+
// ---- What the notes say ------------------------------------------------------
|
|
103
|
+
/** The class bulma-carousel's markup gives a carousel, and bestax `Carousel`'s. */
|
|
104
|
+
export const CAROUSEL_CLASS = 'carousel';
|
|
105
|
+
/** bulma-carousel's class for an image cropped to its frame. */
|
|
106
|
+
export const COVERED_CLASS = 'is-covered';
|
|
107
|
+
/** What bulma-carousel's stylesheet styles `is-covered` on: an `.image`. */
|
|
108
|
+
export const COVERED_SELECTOR = `.image.${COVERED_CLASS}`;
|
|
109
|
+
/** What bestax's stylesheet does with the `carousel` class on markup. */
|
|
110
|
+
const CAROUSEL_STYLED = "which `bestax.css` and `extras.css` style as its root (`position: relative`, `overflow: hidden`, `width: 100%`) until a `Carousel` takes the element's place";
|
|
111
|
+
/** What replaces a carousel, in the place of `where`. */
|
|
112
|
+
function renderCarousel(where) {
|
|
113
|
+
return `render bestax's \`Carousel\` in ${where}, with a \`CarouselItem\` for each slide, and carry the script's options over as the \`html-script:carousel\` recipe says`;
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* The elements a page's script attaches bulma-carousel to: each one a
|
|
117
|
+
* carousel, whose children become its slides, and none of it run by the
|
|
118
|
+
* module.
|
|
119
|
+
*/
|
|
120
|
+
export function drivenMessage(facts) {
|
|
121
|
+
const { selector, script, count, sharedId, carouselClass } = facts;
|
|
122
|
+
const which = count === 1
|
|
123
|
+
? `${script} attaches bulma-carousel to this element (\`${selector}\`)`
|
|
124
|
+
: `${script} attaches bulma-carousel to \`${selector}\`, which selects these ${count} elements${sharedId === undefined
|
|
125
|
+
? ''
|
|
126
|
+
: `, since the page gives each one \`id="${sharedId}"\``}, so each is a carousel`;
|
|
127
|
+
return [
|
|
128
|
+
`${which}: the script makes a slide of each of its children and builds the carousel around them, which the module doesn't do, so ${renderCarousel(count === 1 ? 'its place' : 'the place of each')}`,
|
|
129
|
+
...(carouselClass
|
|
130
|
+
? [
|
|
131
|
+
`\`${CAROUSEL_CLASS}\` is bestax \`Carousel\`'s own class, ${CAROUSEL_STYLED}`,
|
|
132
|
+
]
|
|
133
|
+
: []),
|
|
134
|
+
].join('; ');
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* An element with the `carousel` class on a page that uses bulma-carousel,
|
|
138
|
+
* where no selector the codemod read reaches it.
|
|
139
|
+
*/
|
|
140
|
+
export function carouselClassMessage() {
|
|
141
|
+
return `\`${CAROUSEL_CLASS}\` is the class bulma-carousel's markup gives a carousel, and bestax \`Carousel\`'s own, ${CAROUSEL_STYLED}: if the page's carousel script drives this element, ${renderCarousel('its place')}, and otherwise drop the class or rename it`;
|
|
142
|
+
}
|
|
143
|
+
/** An `.image` with bulma-carousel's `is-covered`. */
|
|
144
|
+
export function coveredMessage() {
|
|
145
|
+
return `\`${COVERED_CLASS}\` is bulma-carousel's class: inside one of the slides its script builds, its stylesheet makes the \`<img>\` in an \`.image\` fill the frame and crops the photo to fit (\`object-fit: cover\`); nothing in bestax reads the class (\`Image\` has no prop for it, and \`Carousel\`'s slides aren't bulma-carousel's), so in the app a ratio image stretches its photo instead: keep the class and give it the rule in the app's stylesheet (\`.image.is-covered img { width: 100%; height: 100%; object-fit: cover; }\`)`;
|
|
146
|
+
}
|
|
@@ -25,6 +25,11 @@ export declare const SCRIPT_PATTERNS: readonly string[];
|
|
|
25
25
|
* Font Awesome, a Bulma extension, jQuery, a web font, or any other.
|
|
26
26
|
*/
|
|
27
27
|
export declare const ASSET_KINDS: readonly string[];
|
|
28
|
+
/**
|
|
29
|
+
* A Bulma extension's own markup on the page (`html-extensions.ts`): an
|
|
30
|
+
* element bulma-carousel's script makes a carousel of, and its `is-covered`.
|
|
31
|
+
*/
|
|
32
|
+
export declare const EXTENSION_MARKUP: readonly string[];
|
|
28
33
|
export declare const HTML_KINDS: ReadonlySet<string>;
|
|
29
34
|
/** Whether a token is one an id of this kind may carry. */
|
|
30
35
|
export declare function inHtmlVocabulary(kind: string, token: string): boolean;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"html-rules.d.ts","sourceRoot":"","sources":["../../../src/sources/bulma-classes/html-rules.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAKH,2EAA2E;AAC3E,eAAO,MAAM,oBAAoB,EAAE,SAAS,MAAM,EASjD,CAAC;AAEF,0EAA0E;AAC1E,eAAO,MAAM,aAAa,EAAE,SAAS,MAAM,EAAkC,CAAC;AAE9E,8EAA8E;AAC9E,eAAO,MAAM,eAAe,EAAE,SAAS,MAAM,EAO5C,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,WAAW,EAAE,SAAS,MAAM,EAQxC,CAAC;
|
|
1
|
+
{"version":3,"file":"html-rules.d.ts","sourceRoot":"","sources":["../../../src/sources/bulma-classes/html-rules.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAKH,2EAA2E;AAC3E,eAAO,MAAM,oBAAoB,EAAE,SAAS,MAAM,EASjD,CAAC;AAEF,0EAA0E;AAC1E,eAAO,MAAM,aAAa,EAAE,SAAS,MAAM,EAAkC,CAAC;AAE9E,8EAA8E;AAC9E,eAAO,MAAM,eAAe,EAAE,SAAS,MAAM,EAO5C,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,WAAW,EAAE,SAAS,MAAM,EAQxC,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,gBAAgB,EAAE,SAAS,MAAM,EAA+B,CAAC;AA4C9E,eAAO,MAAM,UAAU,EAAE,WAAW,CAAC,MAAM,CAAoC,CAAC;AAKhF,2DAA2D;AAC3D,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAErE;AAED,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM,GAAG,MAAM,CAO/D"}
|
|
@@ -51,6 +51,11 @@ export const ASSET_KINDS = [
|
|
|
51
51
|
'stylesheet',
|
|
52
52
|
'webfont',
|
|
53
53
|
];
|
|
54
|
+
/**
|
|
55
|
+
* A Bulma extension's own markup on the page (`html-extensions.ts`): an
|
|
56
|
+
* element bulma-carousel's script makes a carousel of, and its `is-covered`.
|
|
57
|
+
*/
|
|
58
|
+
export const EXTENSION_MARKUP = ['carousel', 'is-covered'];
|
|
54
59
|
/** Every HTML event-handler attribute, as written (`onclick`). */
|
|
55
60
|
const EVENT_ATTRIBUTES = Object.values(html.property)
|
|
56
61
|
.map(info => info.attribute)
|
|
@@ -59,6 +64,7 @@ const VOCABULARY = {
|
|
|
59
64
|
'html-head': new Set(['title', 'meta', 'csp', 'link', 'style', 'base']),
|
|
60
65
|
'html-asset': new Set(ASSET_KINDS),
|
|
61
66
|
'html-script': new Set(SCRIPT_PATTERNS),
|
|
67
|
+
'html-extension': new Set(EXTENSION_MARKUP),
|
|
62
68
|
'html-document': new Set([
|
|
63
69
|
...NAVBAR_FIXED_CLASSES,
|
|
64
70
|
...THEME_CLASSES,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"html.d.ts","sourceRoot":"","sources":["../../../src/sources/bulma-classes/html.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AAIH,OAAO,KAAK,EAEV,UAAU,EACV,aAAa,EACb,SAAS,EACT,gBAAgB,EACjB,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"html.d.ts","sourceRoot":"","sources":["../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CA2Hf;AAgCD,yCAAyC;AACzC,wBAAgB,aAAa,CAC3B,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,MAAM,EACd,SAAS,EAAE,aAAa,GAAG,SAAS,EACpC,OAAO,GAAE,gBAAqB,GAC7B,UAAU,CAGZ"}
|
|
@@ -33,23 +33,16 @@ import path from 'node:path';
|
|
|
33
33
|
import { makeApi, runTransform } from '../../runner.js';
|
|
34
34
|
import { isNumberProp, numberLiteral } from '../_shared/html/attributes.js';
|
|
35
35
|
import { emitJsx } from '../_shared/html/emit.js';
|
|
36
|
-
import { childrenOf, isElement, isText, parseHtml, } from '../_shared/html/parse.js';
|
|
36
|
+
import { attributeOf, childrenOf, classesOf, isElement, isText, parseHtml, } from '../_shared/html/parse.js';
|
|
37
37
|
import { boxOfDisplay, uaDisplay, validInlineDisplay, } from '../_shared/html/whitespace.js';
|
|
38
38
|
import { flaggableRoot } from './class-map.js';
|
|
39
39
|
import { bulmaDisplay, bulmaOutOfFlow, HELPER_DISPLAY } from './display.js';
|
|
40
|
-
import { bulmaBuildMessage, bulmaMediaMessage, bulmaStylesheetMessage, classifyAsset, extensionMessage, fontAwesomeMessage, jqueryMessage, PRIMARY_CLASS, scriptMessage, stylesheetMessage, webfontMessage, } from './html-assets.js';
|
|
40
|
+
import { bulmaBuildMessage, bulmaMediaMessage, bulmaStylesheetMessage, classifyAsset, extensionMessage, extensionPackage, fontAwesomeMessage, jqueryMessage, PRIMARY_CLASS, scriptMessage, stylesheetMessage, webfontMessage, } from './html-assets.js';
|
|
41
|
+
import { CAROUSEL_CLASS, carouselClassMessage, carouselSelectors, COVERED_SELECTOR, coveredMessage, drivenMessage, selectAll, } from './html-extensions.js';
|
|
41
42
|
import { htmlRuleId, NAVBAR_FIXED_CLASSES, THEME_CLASSES, } from './html-rules.js';
|
|
42
43
|
import { inNextApp, writesTypeScript } from './project.js';
|
|
43
44
|
import transform, { FILE_RULES } from './transform.js';
|
|
44
45
|
const HTML_NS = 'http://www.w3.org/1999/xhtml';
|
|
45
|
-
function attributeOf(element, name) {
|
|
46
|
-
return element.attrs.find(attr => attr.name === name && !attr.prefix)?.value;
|
|
47
|
-
}
|
|
48
|
-
function classesOf(element) {
|
|
49
|
-
return (attributeOf(element, 'class') ?? '')
|
|
50
|
-
.split(/[ \t\n\f\r]+/)
|
|
51
|
-
.filter(Boolean);
|
|
52
|
-
}
|
|
53
46
|
function textContent(node) {
|
|
54
47
|
return childrenOf(node)
|
|
55
48
|
.map(child => isText(child) ? child.value : isElement(child) ? textContent(child) : '')
|
|
@@ -333,6 +326,14 @@ function scriptNotes(script, page) {
|
|
|
333
326
|
];
|
|
334
327
|
}
|
|
335
328
|
const code = textContent(script);
|
|
329
|
+
for (const selector of carouselSelectors(code)) {
|
|
330
|
+
page.carousels.push({
|
|
331
|
+
selector,
|
|
332
|
+
script: line === null
|
|
333
|
+
? 'an inline script'
|
|
334
|
+
: `the inline script at line ${line}`,
|
|
335
|
+
});
|
|
336
|
+
}
|
|
336
337
|
const found = SCRIPT_PATTERNS.filter(([, pattern]) => pattern.test(code));
|
|
337
338
|
if (found.length === 0) {
|
|
338
339
|
return [
|
|
@@ -402,10 +403,10 @@ function placeOf(url, dir) {
|
|
|
402
403
|
* the patterns that name what they drive. Null when it can't be read, is too
|
|
403
404
|
* large to be the page's own, or shows none of them.
|
|
404
405
|
*/
|
|
405
|
-
function localScriptNotes(quoted, target,
|
|
406
|
+
function localScriptNotes(quoted, target, page, line) {
|
|
406
407
|
let code;
|
|
407
408
|
try {
|
|
408
|
-
const file = path.resolve(dir, target);
|
|
409
|
+
const file = path.resolve(page.dir, target);
|
|
409
410
|
if (fs.statSync(file).size > LOCAL_SCRIPT_LIMIT)
|
|
410
411
|
return null;
|
|
411
412
|
code = fs.readFileSync(file, 'utf8');
|
|
@@ -413,6 +414,12 @@ function localScriptNotes(quoted, target, dir, line) {
|
|
|
413
414
|
catch {
|
|
414
415
|
return null;
|
|
415
416
|
}
|
|
417
|
+
for (const selector of carouselSelectors(code)) {
|
|
418
|
+
page.carousels.push({
|
|
419
|
+
selector,
|
|
420
|
+
script: `the page's script \`${quoted}\``,
|
|
421
|
+
});
|
|
422
|
+
}
|
|
416
423
|
const found = LOCAL_SCRIPT_PATTERNS.filter(([, pattern]) => pattern.test(code));
|
|
417
424
|
if (found.length === 0)
|
|
418
425
|
return null;
|
|
@@ -543,7 +550,7 @@ function assetNotes(page, root) {
|
|
|
543
550
|
case 'script': {
|
|
544
551
|
const { place, target } = placeOf(load.url, page.dir);
|
|
545
552
|
const local = place === 'beside'
|
|
546
|
-
? localScriptNotes(quoted, target, page
|
|
553
|
+
? localScriptNotes(quoted, target, page, load.line)
|
|
547
554
|
: null;
|
|
548
555
|
if (local)
|
|
549
556
|
notes.push(...local);
|
|
@@ -575,7 +582,10 @@ function assetNotes(page, root) {
|
|
|
575
582
|
}
|
|
576
583
|
else {
|
|
577
584
|
rule = htmlRuleId('html-asset', 'bulma-extension');
|
|
578
|
-
|
|
585
|
+
const kinds = new Set(loads.map(load => load.loads));
|
|
586
|
+
message = extensionMessage(asset.name, quoted, kinds, page.css,
|
|
587
|
+
// Its stylesheet is what crops them (`extensionNotes`).
|
|
588
|
+
kinds.has('stylesheet') && page.covered.length > 0);
|
|
579
589
|
}
|
|
580
590
|
if (message === null)
|
|
581
591
|
continue;
|
|
@@ -588,6 +598,83 @@ function assetNotes(page, root) {
|
|
|
588
598
|
}
|
|
589
599
|
return { notes, importsBulma };
|
|
590
600
|
}
|
|
601
|
+
/** Where a note about several elements goes: the first, and every line. */
|
|
602
|
+
function atElements(elements) {
|
|
603
|
+
const lines = [
|
|
604
|
+
...new Set(elements.flatMap(element => {
|
|
605
|
+
const line = element.sourceCodeLocation?.startLine;
|
|
606
|
+
return line === undefined ? [] : [line];
|
|
607
|
+
})),
|
|
608
|
+
];
|
|
609
|
+
return {
|
|
610
|
+
line: elements[0].sourceCodeLocation?.startLine ?? null,
|
|
611
|
+
...(lines.length > 1 ? { lines } : {}),
|
|
612
|
+
};
|
|
613
|
+
}
|
|
614
|
+
/**
|
|
615
|
+
* bulma-carousel's own markup, which no component converts: each selector
|
|
616
|
+
* the page's scripts attach it to, at the elements it matches; the
|
|
617
|
+
* `carousel` class anywhere else, on a page that uses bulma-carousel; and
|
|
618
|
+
* `is-covered` on an `.image`, on a page that loads its stylesheet, the one
|
|
619
|
+
* thing that styles it. A selector the codemod can't read, or that matches
|
|
620
|
+
* nothing, has no note of its own: the script's note still stands.
|
|
621
|
+
*/
|
|
622
|
+
function extensionNotes(root, page) {
|
|
623
|
+
const notes = [];
|
|
624
|
+
const extensions = page.loads.flatMap(load => {
|
|
625
|
+
const asset = classifyAsset(load.url, load.loads);
|
|
626
|
+
return asset.kind === 'bulma-extension'
|
|
627
|
+
? [{ name: extensionPackage(asset.name), loads: load.loads }]
|
|
628
|
+
: [];
|
|
629
|
+
});
|
|
630
|
+
const driven = new Set();
|
|
631
|
+
const read = new Set();
|
|
632
|
+
for (const { selector, script } of page.carousels) {
|
|
633
|
+
if (read.has(selector))
|
|
634
|
+
continue;
|
|
635
|
+
read.add(selector);
|
|
636
|
+
const elements = selectAll(root, selector, page.quirks) ?? [];
|
|
637
|
+
if (elements.length === 0)
|
|
638
|
+
continue;
|
|
639
|
+
for (const element of elements)
|
|
640
|
+
driven.add(element);
|
|
641
|
+
const ids = new Set(elements.map(element => attributeOf(element, 'id')));
|
|
642
|
+
notes.push({
|
|
643
|
+
rule: htmlRuleId('html-extension', 'carousel'),
|
|
644
|
+
message: drivenMessage({
|
|
645
|
+
selector: quote(selector, 40),
|
|
646
|
+
script,
|
|
647
|
+
count: elements.length,
|
|
648
|
+
sharedId: elements.length > 1 && ids.size === 1 ? [...ids][0] : undefined,
|
|
649
|
+
carouselClass: elements.some(element => classesOf(element).includes(CAROUSEL_CLASS)),
|
|
650
|
+
}),
|
|
651
|
+
...atElements(elements),
|
|
652
|
+
});
|
|
653
|
+
}
|
|
654
|
+
const usesCarousel = page.carousels.length > 0 ||
|
|
655
|
+
extensions.some(({ name }) => ['bulma-carousel', 'bulma-extensions'].includes(name));
|
|
656
|
+
// A class's TODO is about the app's stylesheets, which read it in its own
|
|
657
|
+
// case: only what a script selects follows the page's quirks.
|
|
658
|
+
const classed = usesCarousel
|
|
659
|
+
? selectAll(root, `.${CAROUSEL_CLASS}`, false).filter(element => !driven.has(element))
|
|
660
|
+
: [];
|
|
661
|
+
if (classed.length > 0) {
|
|
662
|
+
notes.push({
|
|
663
|
+
rule: htmlRuleId('html-extension', 'carousel'),
|
|
664
|
+
message: carouselClassMessage(),
|
|
665
|
+
...atElements(classed),
|
|
666
|
+
});
|
|
667
|
+
}
|
|
668
|
+
const cropped = extensions.some(({ name, loads }) => name === 'bulma-carousel' && loads === 'stylesheet');
|
|
669
|
+
if (cropped && page.covered.length > 0) {
|
|
670
|
+
notes.push({
|
|
671
|
+
rule: htmlRuleId('html-extension', 'is-covered'),
|
|
672
|
+
message: coveredMessage(),
|
|
673
|
+
...atElements(page.covered),
|
|
674
|
+
});
|
|
675
|
+
}
|
|
676
|
+
return notes;
|
|
677
|
+
}
|
|
591
678
|
/** A `<meta http-equiv>` that sets the page's Content Security Policy. */
|
|
592
679
|
function isCsp(meta) {
|
|
593
680
|
return ((attributeOf(meta, 'http-equiv') ?? '').trim().toLowerCase() ===
|
|
@@ -1209,7 +1296,11 @@ export function convertPage(file, source, collector, options = {}) {
|
|
|
1209
1296
|
dir: path.dirname(file),
|
|
1210
1297
|
css: options.cssMode ?? 'keep',
|
|
1211
1298
|
nextjs: inNextApp(file, options.packageLanguages),
|
|
1299
|
+
quirks: parsed.quirks,
|
|
1212
1300
|
loads: [],
|
|
1301
|
+
carousels: [],
|
|
1302
|
+
// In its own case, as the rule the TODO gives the app reads it.
|
|
1303
|
+
covered: selectAll(parsed.root, COVERED_SELECTOR, false),
|
|
1213
1304
|
};
|
|
1214
1305
|
parseNotes(parsed, notes.document);
|
|
1215
1306
|
headNotes(parsed.head, notes.document, context);
|
|
@@ -1221,6 +1312,7 @@ export function convertPage(file, source, collector, options = {}) {
|
|
|
1221
1312
|
dropScripts(parsed.root, notes.document, context);
|
|
1222
1313
|
const assets = assetNotes(context, parsed.root);
|
|
1223
1314
|
notes.document.push(...assets.notes);
|
|
1315
|
+
notes.content.push(...extensionNotes(parsed.root, context));
|
|
1224
1316
|
const emitted = emitJsx(parsed.root, {
|
|
1225
1317
|
displayOf: pageDisplayOf,
|
|
1226
1318
|
indent: 2,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "bestax-migrate",
|
|
3
|
-
"version": "2.32.
|
|
3
|
+
"version": "2.32.1",
|
|
4
4
|
"description": "Codemods for migrating existing React apps from other Bulma libraries to @allxsmith/bestax-bulma",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
"jscodeshift": "^17.3.0",
|
|
41
41
|
"parse5": "^7.3.0",
|
|
42
42
|
"property-information": "^7.2.0",
|
|
43
|
-
"@allxsmith/bestax-bulma": "^5.
|
|
43
|
+
"@allxsmith/bestax-bulma": "^5.45.0"
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
46
|
"@jest/globals": "^30.0.0",
|