bestax-migrate 2.31.3 → 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/class-map.d.ts +1 -1
- package/dist/sources/bulma-classes/html-assets.d.ts +22 -2
- package/dist/sources/bulma-classes/html-assets.d.ts.map +1 -1
- package/dist/sources/bulma-classes/html-assets.js +35 -7
- 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 +165 -15
- package/dist/sources/bulma-classes/plan.d.ts.map +1 -1
- package/dist/sources/bulma-classes/plan.js +66 -0
- 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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G,UAAU,CA4DpD"}
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
* `<noscript>` holds markup rather than text, which is what it means to
|
|
12
12
|
* someone reading 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
|
}
|
|
@@ -57,7 +57,7 @@ export interface Modifier {
|
|
|
57
57
|
* sizes the element the same without picking its tag (`textSize`, whose
|
|
58
58
|
* `is-size-4` Bulma sizes as it does `Title`'s `is-4`). The MCP lookup reads
|
|
59
59
|
* it, and the truth e2e holds it to Bulma's stylesheet; the codemod writes
|
|
60
|
-
* it nowhere,
|
|
60
|
+
* it nowhere, since its class differs, and names it in a TODO instead.
|
|
61
61
|
*/
|
|
62
62
|
readonly offTag?: PropWrite;
|
|
63
63
|
/**
|
|
@@ -75,13 +75,33 @@ 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';
|
|
82
89
|
}>, quoted: string): string;
|
|
83
90
|
/** Where a stylesheet or script is, read beside the page. */
|
|
84
91
|
export type Place = 'beside' | 'missing' | 'elsewhere';
|
|
85
|
-
|
|
92
|
+
/**
|
|
93
|
+
* The relative URLs in a stylesheet of the page's own (its `url()`s and
|
|
94
|
+
* `@import`s), which resolve against the stylesheet's folder rather than the
|
|
95
|
+
* page's, as its TODO names them: each list already quoted and in backticks.
|
|
96
|
+
*/
|
|
97
|
+
export interface StylesheetUrls {
|
|
98
|
+
/** The stylesheet's folder, from the page's, or null for the page's own. */
|
|
99
|
+
folder: string | null;
|
|
100
|
+
/** The URLs as they are written. */
|
|
101
|
+
written: string;
|
|
102
|
+
/** The ones inside the page's folder, from the site root, or null if none is. */
|
|
103
|
+
fromRoot: string | null;
|
|
104
|
+
}
|
|
105
|
+
export declare function stylesheetMessage(quoted: string, place: Place, target: string, urls?: StylesheetUrls): string;
|
|
86
106
|
export declare function scriptMessage(quoted: string, place: Place, target: string): string;
|
|
87
107
|
//# sourceMappingURL=html-assets.d.ts.map
|
|
@@ -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,GACtB;IAAE,IAAI,EAAE,QAAQ,CAAA;CAAE,CAAC;
|
|
1
|
+
{"version":3,"file":"html-assets.d.ts","sourceRoot":"","sources":["../../../src/sources/bulma-classes/html-assets.ts"],"names":[],"mappings":"AAAA;;;;;;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AAiF;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
|
}
|
|
@@ -222,11 +247,14 @@ export function webfontMessage(asset, quoted) {
|
|
|
222
247
|
}
|
|
223
248
|
return `the page loads a web font's stylesheet from \`${quoted}\`, and a component doesn't: keep the \`<link>\` in the app's index.html, with the preconnects that go with it, or self-host the font and import it from the app's entry`;
|
|
224
249
|
}
|
|
225
|
-
export function stylesheetMessage(quoted, place, target) {
|
|
250
|
+
export function stylesheetMessage(quoted, place, target, urls) {
|
|
226
251
|
if (place === 'beside') {
|
|
227
252
|
// Beside the page is inside its folder, so this never climbs out of it.
|
|
228
253
|
const specifier = `./${target.replace(/^(?:\.\/)+/, '')}`;
|
|
229
|
-
|
|
254
|
+
const moved = urls
|
|
255
|
+
? `; the relative URLs in it (${urls.written}) resolve against ${urls.folder === null ? "the stylesheet's folder, the page's" : `\`${urls.folder}/\`, the stylesheet's folder`}, so moving its rules into the app's stylesheet (such as \`src/index.css\`) means rewriting each against that file's folder, or copying the files into the app's \`public/\` folder and pointing at them from the site root${urls.fromRoot === null ? '' : ` (${urls.fromRoot})`}`
|
|
256
|
+
: '';
|
|
257
|
+
return `the page's own stylesheet \`${quoted}\` is beside it, and a component doesn't load it: import it once for the app, in the order the page loads it, so its rules still win over Bulma's where they did (a module beside the page imports it as \`${specifier}\`), or move its rules into the app's stylesheet${moved}`;
|
|
230
258
|
}
|
|
231
259
|
// Only what the page's folder shows: a `<base href>` may have sent the
|
|
232
260
|
// browser somewhere else, so nothing here says the page never loaded it.
|
|
@@ -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":["../../../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;AAiBxB,OAAO,EAIL,KAAK,SAAS,EAEf,MAAM,+BAA+B,CAAC;AAkEvC;;;;;;;GAOG;AACH,wBAAgB,WAAW,CAAC,QAAQ,EAAE,WAAW,CAAC,MAAM,CAAC,GAAG,MAAM,CAYjE;AAED;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,aAAa,EAAE,SAoB3B,CAAC;AAsBF;;;;;;;;;;;;GAYG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,OAAO,GAAG,MAAM,CAgBnE;AAYD,6DAA6D;AAC7D,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,CAmBlD;AAED;;;GAGG;AACH,wBAAgB,aAAa,CAC3B,IAAI,EAAE,MAAM,EACZ,OAAO,GAAE,gBAAqB,GAC7B,MAAM,CAQR;AAsBD;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,SAAS,GAAG,IAAI,CAU3E;AAkMD,+EAA+E;AAC/E,eAAO,MAAM,YAAY,wCAAsC,CAAC;AA48BhE;;;;;;GAMG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CA4BjD;AAID,+EAA+E;AAC/E,MAAM,WAAW,aAAc,SAAQ,UAAU;IAC/C,2EAA2E;IAC3E,YAAY,EAAE,MAAM,GAAG,IAAI,CAAC;CAC7B;AAWD,wBAAgB,WAAW,CACzB,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,MAAM,EACd,SAAS,EAAE,aAAa,GAAG,SAAS,EACpC,OAAO,GAAE,gBAAqB,GAC7B,aAAa,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;
|
|
@@ -422,6 +429,63 @@ function localScriptNotes(quoted, target, dir, line) {
|
|
|
422
429
|
line,
|
|
423
430
|
}));
|
|
424
431
|
}
|
|
432
|
+
/** Larger than this, a stylesheet beside the page is a bundle, not the page's. */
|
|
433
|
+
const LOCAL_STYLESHEET_LIMIT = 256 * 1024;
|
|
434
|
+
/**
|
|
435
|
+
* A URL a stylesheet names a file with: a `url()`'s, double-quoted,
|
|
436
|
+
* single-quoted or bare, or an `@import`'s, as a string. An `image-set()`
|
|
437
|
+
* can name one as a bare string too, which a regex can't tell from the
|
|
438
|
+
* `type()` string beside it, so that form is left to the recipe.
|
|
439
|
+
*/
|
|
440
|
+
const CSS_URL = /\burl\(\s*(?:"([^"]*)"|'([^']*)'|([^)'"\s]*))\s*\)|@import\s+(?:"([^"]*)"|'([^']*)')/gi;
|
|
441
|
+
/** Values in backticks, each shortened: the first six, then an ellipsis. */
|
|
442
|
+
function codeList(values) {
|
|
443
|
+
const shown = values.slice(0, 6).map(value => `\`${quote(value, 40)}\``);
|
|
444
|
+
return values.length > 6 ? `${shown.join(', ')}, …` : shown.join(', ');
|
|
445
|
+
}
|
|
446
|
+
/**
|
|
447
|
+
* The relative URLs in a stylesheet beside the page (`CSS_URL`), which
|
|
448
|
+
* resolve against the stylesheet's own folder: what moving its rules has to
|
|
449
|
+
* rewrite, each also from the site root when it stays inside the page's
|
|
450
|
+
* folder. Read from the URL as written, so a path from the root is still a
|
|
451
|
+
* URL. Null when the file can't be read, is too large to be the page's own,
|
|
452
|
+
* or names none.
|
|
453
|
+
*/
|
|
454
|
+
function stylesheetUrls(url, dir) {
|
|
455
|
+
let css;
|
|
456
|
+
try {
|
|
457
|
+
const file = path.resolve(dir, urlPath(url));
|
|
458
|
+
if (fs.statSync(file).size > LOCAL_STYLESHEET_LIMIT)
|
|
459
|
+
return null;
|
|
460
|
+
css = fs.readFileSync(file, 'utf8');
|
|
461
|
+
}
|
|
462
|
+
catch {
|
|
463
|
+
return null;
|
|
464
|
+
}
|
|
465
|
+
const written = [
|
|
466
|
+
...new Set([...css.replace(/\/\*[\s\S]*?\*\//g, '').matchAll(CSS_URL)]
|
|
467
|
+
.map(([, ...forms]) => forms.find(form => form !== undefined).trim())
|
|
468
|
+
.filter(isRelative)),
|
|
469
|
+
];
|
|
470
|
+
if (written.length === 0)
|
|
471
|
+
return null;
|
|
472
|
+
const folder = path.posix.dirname(path.posix.normalize(url.trim().replace(/[?#].*$/, '')));
|
|
473
|
+
// Two spellings of one file (`img/a.png`, `./img/a.png`) are one path.
|
|
474
|
+
const fromRoot = [
|
|
475
|
+
...new Set(written.flatMap(each => {
|
|
476
|
+
const [, file, rest] = /^([^?#]*)([\s\S]*)$/.exec(each);
|
|
477
|
+
const joined = path.posix.normalize(path.posix.join(folder, file));
|
|
478
|
+
return joined === '..' || joined.startsWith('../')
|
|
479
|
+
? []
|
|
480
|
+
: [`/${joined}${rest}`];
|
|
481
|
+
})),
|
|
482
|
+
];
|
|
483
|
+
return {
|
|
484
|
+
folder: folder === '.' ? null : quote(folder),
|
|
485
|
+
written: codeList(written),
|
|
486
|
+
fromRoot: fromRoot.length > 0 ? codeList(fromRoot) : null,
|
|
487
|
+
};
|
|
488
|
+
}
|
|
425
489
|
/** Whether the page's markup has a primary color class. */
|
|
426
490
|
function usesPrimary(root) {
|
|
427
491
|
return childrenOf(root).some(child => isElement(child) &&
|
|
@@ -479,13 +543,14 @@ function assetNotes(page, root) {
|
|
|
479
543
|
break;
|
|
480
544
|
case 'stylesheet': {
|
|
481
545
|
const { place, target } = placeOf(load.url, page.dir);
|
|
482
|
-
|
|
546
|
+
const urls = place === 'beside' ? stylesheetUrls(load.url, page.dir) : null;
|
|
547
|
+
note(htmlRuleId('html-asset', 'stylesheet'), stylesheetMessage(quoted, place, quote(target), urls ?? undefined), load.line);
|
|
483
548
|
break;
|
|
484
549
|
}
|
|
485
550
|
case 'script': {
|
|
486
551
|
const { place, target } = placeOf(load.url, page.dir);
|
|
487
552
|
const local = place === 'beside'
|
|
488
|
-
? localScriptNotes(quoted, target, page
|
|
553
|
+
? localScriptNotes(quoted, target, page, load.line)
|
|
489
554
|
: null;
|
|
490
555
|
if (local)
|
|
491
556
|
notes.push(...local);
|
|
@@ -517,7 +582,10 @@ function assetNotes(page, root) {
|
|
|
517
582
|
}
|
|
518
583
|
else {
|
|
519
584
|
rule = htmlRuleId('html-asset', 'bulma-extension');
|
|
520
|
-
|
|
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);
|
|
521
589
|
}
|
|
522
590
|
if (message === null)
|
|
523
591
|
continue;
|
|
@@ -530,6 +598,83 @@ function assetNotes(page, root) {
|
|
|
530
598
|
}
|
|
531
599
|
return { notes, importsBulma };
|
|
532
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
|
+
}
|
|
533
678
|
/** A `<meta http-equiv>` that sets the page's Content Security Policy. */
|
|
534
679
|
function isCsp(meta) {
|
|
535
680
|
return ((attributeOf(meta, 'http-equiv') ?? '').trim().toLowerCase() ===
|
|
@@ -1151,7 +1296,11 @@ export function convertPage(file, source, collector, options = {}) {
|
|
|
1151
1296
|
dir: path.dirname(file),
|
|
1152
1297
|
css: options.cssMode ?? 'keep',
|
|
1153
1298
|
nextjs: inNextApp(file, options.packageLanguages),
|
|
1299
|
+
quirks: parsed.quirks,
|
|
1154
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),
|
|
1155
1304
|
};
|
|
1156
1305
|
parseNotes(parsed, notes.document);
|
|
1157
1306
|
headNotes(parsed.head, notes.document, context);
|
|
@@ -1163,6 +1312,7 @@ export function convertPage(file, source, collector, options = {}) {
|
|
|
1163
1312
|
dropScripts(parsed.root, notes.document, context);
|
|
1164
1313
|
const assets = assetNotes(context, parsed.root);
|
|
1165
1314
|
notes.document.push(...assets.notes);
|
|
1315
|
+
notes.content.push(...extensionNotes(parsed.root, context));
|
|
1166
1316
|
const emitted = emitJsx(parsed.root, {
|
|
1167
1317
|
displayOf: pageDisplayOf,
|
|
1168
1318
|
indent: 2,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plan.d.ts","sourceRoot":"","sources":["../../../src/sources/bulma-classes/plan.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;
|
|
1
|
+
{"version":3,"file":"plan.d.ts","sourceRoot":"","sources":["../../../src/sources/bulma-classes/plan.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAwBH,OAAO,EAKL,KAAK,KAAK,EACX,MAAM,YAAY,CAAC;AAIpB,MAAM,WAAW,YAAY;IAC3B,GA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IAAI,CAKpD;AAED,8DAA8D;AAC9D,MAAM,WAAW,SAAS;IACxB,6DAA6D;IAC7D,KAAK,EAAE,MAAM,CAAC;IACd;;;OAGG;IACH,KAAK,EAAE,KAAK,CAAC,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,MAAM,EAAE,CAAC,CAAC,CAAC;IACvE,0EAA0E;IAC1E,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,yDAAyD;IACzD,IAAI,EAAE,MAAM,EAAE,CAAC;IACf,2DAA2D;IAC3D,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,iCAAiC;IACjC,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,IAAI;IACnB,UAAU,EAAE,UAAU,GAAG,IAAI,CAAC;IAC9B;;;OAGG;IACH,IAAI,CAAC,EAAE;QACL,MAAM,EAAE,MAAM,CAAC;QACf,KAAK,EAAE,KAAK,CAAC,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC,CAAC,CAAC;QACnD,OAAO,EAAE,MAAM,EAAE,CAAC;KACnB,CAAC;IACF,KAAK,EAAE,IAAI,EAAE,CAAC;CACf;AAgLD,wBAAgB,IAAI,CAAC,KAAK,EAAE,YAAY,GAAG,IAAI,CAsB9C"}
|
|
@@ -105,6 +105,70 @@ function secondComponents(carried, fixed, root, target, tag, rendered) {
|
|
|
105
105
|
];
|
|
106
106
|
});
|
|
107
107
|
}
|
|
108
|
+
/** A prop as a TODO writes it: `isLight`, `size="3"`, `minCol={8}`. */
|
|
109
|
+
function propText(write) {
|
|
110
|
+
if (write.value === undefined)
|
|
111
|
+
return `\`${write.prop}\``;
|
|
112
|
+
return write.numeric
|
|
113
|
+
? `\`${write.prop}={${write.value}}\``
|
|
114
|
+
: `\`${write.prop}="${write.value}"\``;
|
|
115
|
+
}
|
|
116
|
+
/** Whether a class is one of the root's colors, as its `color` prop. */
|
|
117
|
+
function isColor(entry, token) {
|
|
118
|
+
return (modifierFor(entry, token)?.writes.some(write => write.prop === 'color') ??
|
|
119
|
+
false);
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* A TODO for each other color class on an element that converts (`button
|
|
123
|
+
* is-black is-primary`). The component takes one `color`, the first class
|
|
124
|
+
* for it, and the other stays in `className`, which renders the same, but
|
|
125
|
+
* two colors on one element look the way Bulma's stylesheet settles them,
|
|
126
|
+
* whatever order they're written in, so each says which one `color` took.
|
|
127
|
+
* Only the classes the element always carries: one a condition adds is a
|
|
128
|
+
* state the page asks for on purpose.
|
|
129
|
+
*/
|
|
130
|
+
function secondColors(entry, root, target, tokens, converted, writes) {
|
|
131
|
+
const first = tokens.find(token => converted.has(token) && isColor(entry, token));
|
|
132
|
+
const color = writes.get('color');
|
|
133
|
+
if (!root || !first || typeof color !== 'string')
|
|
134
|
+
return [];
|
|
135
|
+
return tokens
|
|
136
|
+
.filter(token => !converted.has(token) && isColor(entry, token))
|
|
137
|
+
.map(token => ({
|
|
138
|
+
rule: ruleId('modifier', root),
|
|
139
|
+
message: `\`.${token}\` is a second color on this element, and bestax \`${target}\` takes one \`color\`: \`color="${color}"\` here, from \`.${first}\`, which comes first, so \`.${token}\` stays in its \`className\`, which renders the same; two colors on one element look the way Bulma's stylesheet settles them, whatever order they're written in, so check what the page shows, write the color you want as \`color\`, and drop the other class`,
|
|
140
|
+
}));
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* A TODO for a size class left in `className` off the tags it converts on
|
|
144
|
+
* (`is-3` on an <h1>, which `Title`'s `size="3"` would render as an <h3>),
|
|
145
|
+
* naming the prop that sizes the element the same and keeps its tag
|
|
146
|
+
* (`offTag`, `textSize`), as the MCP lookup names it. Only for the one size
|
|
147
|
+
* class on the element, and only while nothing else writes that prop (an
|
|
148
|
+
* `is-size-2` beside it): with two, the prop would size it differently.
|
|
149
|
+
*/
|
|
150
|
+
function offTagSizes(entry, root, target, tag, tokens, converted, writes) {
|
|
151
|
+
const sizes = tokens.filter(token => modifierFor(entry, token)?.offTag);
|
|
152
|
+
if (!root || sizes.length !== 1 || converted.has(sizes[0]))
|
|
153
|
+
return [];
|
|
154
|
+
const [token] = sizes;
|
|
155
|
+
const modifier = modifierFor(entry, token);
|
|
156
|
+
const off = modifier.offTag;
|
|
157
|
+
const left = entry.noHelpers ||
|
|
158
|
+
(entry.helpersLeftOut !== undefined &&
|
|
159
|
+
Object.hasOwn(entry.helpersLeftOut, off.prop));
|
|
160
|
+
if (left || writes.has(off.prop) || !modifier.tagIn)
|
|
161
|
+
return [];
|
|
162
|
+
const on = modifier.tagIn.map(each => aTag(each)).join(' or ');
|
|
163
|
+
// The truth e2e holds the class the prop renders to the font size Bulma
|
|
164
|
+
// gives the class it stands in for.
|
|
165
|
+
return [
|
|
166
|
+
{
|
|
167
|
+
rule: ruleId('modifier', root),
|
|
168
|
+
message: `\`.${token}\` stays in its \`className\`, which renders the same: bestax \`${target}\` renders it exactly only on ${on}, as ${modifier.writes.map(propText).join(' ')}; on this <${tag}>, write ${propText(off)} in its place, which sizes it the same and keeps the <${tag}>, though \`${off.prop}\` renders a Bulma helper class, which is \`!important\`: check the page's own CSS sets no size on it`,
|
|
169
|
+
},
|
|
170
|
+
];
|
|
171
|
+
}
|
|
108
172
|
/**
|
|
109
173
|
* Every class the element may carry: its fixed ones, and any a condition
|
|
110
174
|
* adds, which the element has to be right with as well as without.
|
|
@@ -563,6 +627,8 @@ function planElement(facts) {
|
|
|
563
627
|
return refuse('attr', 'className', `bestax \`${target}\` writes a \`className\` it's given in place of \`.${root}\`, so this converts only with no other class; keep it as markup`);
|
|
564
628
|
}
|
|
565
629
|
todos.push(...secondComponents(carried, tokens, root, target, tag, rendered));
|
|
630
|
+
todos.push(...secondColors(entry, root, target, tokens, converted, writes));
|
|
631
|
+
todos.push(...offTagSizes(entry, root, target, tag, tokens, converted, writes));
|
|
566
632
|
// A glyph the target renders from props takes the place of the only child.
|
|
567
633
|
const glyph = moved ?? (entry.readsGlyph ? readGlyph(facts.soleChild) : undefined);
|
|
568
634
|
return {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "bestax-migrate",
|
|
3
|
-
"version": "2.
|
|
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",
|