@wordpress/block-editor 12.12.0 → 12.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +12 -10
- package/README.md +35 -3
- package/build/components/block-alignment-control/use-available-alignments.js +30 -28
- package/build/components/block-alignment-control/use-available-alignments.js.map +1 -1
- package/build/components/block-list/block.native.js +4 -4
- package/build/components/block-list/block.native.js.map +1 -1
- package/build/components/block-list/layout.js +2 -3
- package/build/components/block-list/layout.js.map +1 -1
- package/build/components/border-radius-control/index.js +3 -2
- package/build/components/border-radius-control/index.js.map +1 -1
- package/build/components/color-palette/with-color-context.js +6 -6
- package/build/components/color-palette/with-color-context.js.map +1 -1
- package/build/components/colors/with-colors.js +2 -8
- package/build/components/colors/with-colors.js.map +1 -1
- package/build/components/colors-gradients/control.js +6 -7
- package/build/components/colors-gradients/control.js.map +1 -1
- package/build/components/colors-gradients/use-multiple-origin-colors-and-gradients.js +5 -13
- package/build/components/colors-gradients/use-multiple-origin-colors-and-gradients.js.map +1 -1
- package/build/components/font-family/index.js +2 -3
- package/build/components/font-family/index.js.map +1 -1
- package/build/components/font-sizes/font-size-picker.js +3 -5
- package/build/components/font-sizes/font-size-picker.js.map +1 -1
- package/build/components/font-sizes/with-font-sizes.js +3 -4
- package/build/components/font-sizes/with-font-sizes.js.map +1 -1
- package/build/components/global-styles/filters-panel.js +7 -8
- package/build/components/global-styles/filters-panel.js.map +1 -1
- package/build/components/global-styles/image-settings-panel.js +2 -2
- package/build/components/global-styles/image-settings-panel.js.map +1 -1
- package/build/components/global-styles/typography-panel.js +1 -1
- package/build/components/global-styles/typography-panel.js.map +1 -1
- package/build/components/gradients/use-gradient.js +2 -5
- package/build/components/gradients/use-gradient.js.map +1 -1
- package/build/components/height-control/index.js +3 -3
- package/build/components/height-control/index.js.map +1 -1
- package/build/components/index.js +9 -2
- package/build/components/index.js.map +1 -1
- package/build/components/index.native.js +9 -2
- package/build/components/index.native.js.map +1 -1
- package/build/components/inner-blocks/index.js +2 -2
- package/build/components/inner-blocks/index.js.map +1 -1
- package/build/components/letter-spacing-control/index.js +3 -3
- package/build/components/letter-spacing-control/index.js.map +1 -1
- package/build/components/link-control/search-item.js +11 -0
- package/build/components/link-control/search-item.js.map +1 -1
- package/build/components/link-control/search-results.js +2 -1
- package/build/components/link-control/search-results.js.map +1 -1
- package/build/components/link-control/use-search-handler.js +10 -5
- package/build/components/link-control/use-search-handler.js.map +1 -1
- package/build/components/resizable-box-popover/index.js +1 -1
- package/build/components/resizable-box-popover/index.js.map +1 -1
- package/build/components/rich-text/index.js +1 -1
- package/build/components/rich-text/index.js.map +1 -1
- package/build/components/spacing-sizes-control/hooks/use-spacing-sizes.js +6 -3
- package/build/components/spacing-sizes-control/hooks/use-spacing-sizes.js.map +1 -1
- package/build/components/spacing-sizes-control/input-controls/spacing-input-control.js +3 -3
- package/build/components/spacing-sizes-control/input-controls/spacing-input-control.js.map +1 -1
- package/build/components/unit-control/index.js +3 -3
- package/build/components/unit-control/index.js.map +1 -1
- package/build/components/use-block-commands/index.js +6 -1
- package/build/components/use-block-commands/index.js.map +1 -1
- package/build/components/use-settings/index.js +212 -0
- package/build/components/use-settings/index.js.map +1 -0
- package/build/hooks/align.js +51 -35
- package/build/hooks/align.js.map +1 -1
- package/build/hooks/anchor.js +37 -32
- package/build/hooks/anchor.js.map +1 -1
- package/build/hooks/background.js +4 -4
- package/build/hooks/background.js.map +1 -1
- package/build/hooks/color.js +2 -4
- package/build/hooks/color.js.map +1 -1
- package/build/hooks/duotone.js +10 -9
- package/build/hooks/duotone.js.map +1 -1
- package/build/hooks/font-size.js +4 -4
- package/build/hooks/font-size.js.map +1 -1
- package/build/hooks/layout.js +10 -11
- package/build/hooks/layout.js.map +1 -1
- package/build/hooks/line-height.js +3 -3
- package/build/hooks/line-height.js.map +1 -1
- package/build/hooks/position.js +2 -3
- package/build/hooks/position.js.map +1 -1
- package/build/hooks/use-color-props.js +3 -11
- package/build/hooks/use-color-props.js.map +1 -1
- package/build/hooks/utils.js +1 -42
- package/build/hooks/utils.js.map +1 -1
- package/build/layouts/constrained.js +3 -3
- package/build/layouts/constrained.js.map +1 -1
- package/build/utils/object.js +4 -1
- package/build/utils/object.js.map +1 -1
- package/build/utils/transform-styles/index.js +19 -24
- package/build/utils/transform-styles/index.js.map +1 -1
- package/build-module/components/block-alignment-control/use-available-alignments.js +30 -28
- package/build-module/components/block-alignment-control/use-available-alignments.js.map +1 -1
- package/build-module/components/block-list/block.native.js +4 -4
- package/build-module/components/block-list/block.native.js.map +1 -1
- package/build-module/components/block-list/layout.js +2 -2
- package/build-module/components/block-list/layout.js.map +1 -1
- package/build-module/components/border-radius-control/index.js +3 -2
- package/build-module/components/border-radius-control/index.js.map +1 -1
- package/build-module/components/color-palette/with-color-context.js +6 -5
- package/build-module/components/color-palette/with-color-context.js.map +1 -1
- package/build-module/components/colors/with-colors.js +2 -7
- package/build-module/components/colors/with-colors.js.map +1 -1
- package/build-module/components/colors-gradients/control.js +6 -7
- package/build-module/components/colors-gradients/control.js.map +1 -1
- package/build-module/components/colors-gradients/use-multiple-origin-colors-and-gradients.js +5 -12
- package/build-module/components/colors-gradients/use-multiple-origin-colors-and-gradients.js.map +1 -1
- package/build-module/components/font-family/index.js +2 -2
- package/build-module/components/font-family/index.js.map +1 -1
- package/build-module/components/font-sizes/font-size-picker.js +3 -4
- package/build-module/components/font-sizes/font-size-picker.js.map +1 -1
- package/build-module/components/font-sizes/with-font-sizes.js +3 -3
- package/build-module/components/font-sizes/with-font-sizes.js.map +1 -1
- package/build-module/components/global-styles/filters-panel.js +7 -8
- package/build-module/components/global-styles/filters-panel.js.map +1 -1
- package/build-module/components/global-styles/image-settings-panel.js +2 -2
- package/build-module/components/global-styles/image-settings-panel.js.map +1 -1
- package/build-module/components/global-styles/typography-panel.js +1 -1
- package/build-module/components/global-styles/typography-panel.js.map +1 -1
- package/build-module/components/gradients/use-gradient.js +2 -4
- package/build-module/components/gradients/use-gradient.js.map +1 -1
- package/build-module/components/height-control/index.js +3 -2
- package/build-module/components/height-control/index.js.map +1 -1
- package/build-module/components/index.js +1 -1
- package/build-module/components/index.js.map +1 -1
- package/build-module/components/index.native.js +1 -1
- package/build-module/components/index.native.js.map +1 -1
- package/build-module/components/inner-blocks/index.js +2 -2
- package/build-module/components/inner-blocks/index.js.map +1 -1
- package/build-module/components/letter-spacing-control/index.js +3 -2
- package/build-module/components/letter-spacing-control/index.js.map +1 -1
- package/build-module/components/link-control/search-item.js +12 -1
- package/build-module/components/link-control/search-item.js.map +1 -1
- package/build-module/components/link-control/search-results.js +2 -1
- package/build-module/components/link-control/search-results.js.map +1 -1
- package/build-module/components/link-control/use-search-handler.js +10 -5
- package/build-module/components/link-control/use-search-handler.js.map +1 -1
- package/build-module/components/resizable-box-popover/index.js +1 -1
- package/build-module/components/resizable-box-popover/index.js.map +1 -1
- package/build-module/components/rich-text/index.js +1 -1
- package/build-module/components/rich-text/index.js.map +1 -1
- package/build-module/components/spacing-sizes-control/hooks/use-spacing-sizes.js +6 -2
- package/build-module/components/spacing-sizes-control/hooks/use-spacing-sizes.js.map +1 -1
- package/build-module/components/spacing-sizes-control/input-controls/spacing-input-control.js +3 -2
- package/build-module/components/spacing-sizes-control/input-controls/spacing-input-control.js.map +1 -1
- package/build-module/components/unit-control/index.js +3 -2
- package/build-module/components/unit-control/index.js.map +1 -1
- package/build-module/components/use-block-commands/index.js +5 -1
- package/build-module/components/use-block-commands/index.js.map +1 -1
- package/build-module/components/use-settings/index.js +203 -0
- package/build-module/components/use-settings/index.js.map +1 -0
- package/build-module/hooks/align.js +51 -35
- package/build-module/hooks/align.js.map +1 -1
- package/build-module/hooks/anchor.js +37 -32
- package/build-module/hooks/anchor.js.map +1 -1
- package/build-module/hooks/background.js +4 -4
- package/build-module/hooks/background.js.map +1 -1
- package/build-module/hooks/color.js +2 -4
- package/build-module/hooks/color.js.map +1 -1
- package/build-module/hooks/duotone.js +11 -10
- package/build-module/hooks/duotone.js.map +1 -1
- package/build-module/hooks/font-size.js +4 -4
- package/build-module/hooks/font-size.js.map +1 -1
- package/build-module/hooks/layout.js +10 -11
- package/build-module/hooks/layout.js.map +1 -1
- package/build-module/hooks/line-height.js +3 -3
- package/build-module/hooks/line-height.js.map +1 -1
- package/build-module/hooks/position.js +2 -3
- package/build-module/hooks/position.js.map +1 -1
- package/build-module/hooks/use-color-props.js +3 -11
- package/build-module/hooks/use-color-props.js.map +1 -1
- package/build-module/hooks/utils.js +2 -43
- package/build-module/hooks/utils.js.map +1 -1
- package/build-module/layouts/constrained.js +3 -2
- package/build-module/layouts/constrained.js.map +1 -1
- package/build-module/utils/object.js +3 -1
- package/build-module/utils/object.js.map +1 -1
- package/build-module/utils/transform-styles/index.js +20 -24
- package/build-module/utils/transform-styles/index.js.map +1 -1
- package/build-style/style-rtl.css +13 -6
- package/build-style/style.css +13 -6
- package/package.json +36 -34
- package/src/components/block-alignment-control/use-available-alignments.js +49 -34
- package/src/components/block-list/block.native.js +4 -4
- package/src/components/block-list/layout.js +2 -2
- package/src/components/block-styles/style.scss +1 -1
- package/src/components/border-radius-control/index.js +3 -2
- package/src/components/color-palette/with-color-context.js +9 -9
- package/src/components/colors/with-colors.js +6 -7
- package/src/components/colors-gradients/control.js +10 -7
- package/src/components/colors-gradients/use-multiple-origin-colors-and-gradients.js +29 -15
- package/src/components/font-family/index.js +2 -2
- package/src/components/font-sizes/font-size-picker.js +6 -4
- package/src/components/font-sizes/with-font-sizes.js +3 -5
- package/src/components/global-styles/filters-panel.js +9 -15
- package/src/components/global-styles/image-settings-panel.js +2 -2
- package/src/components/global-styles/typography-panel.js +1 -1
- package/src/components/gradients/use-gradient.js +10 -4
- package/src/components/height-control/index.js +3 -2
- package/src/components/index.js +1 -1
- package/src/components/index.native.js +1 -1
- package/src/components/inner-blocks/index.js +2 -2
- package/src/components/inserter/style.scss +9 -1
- package/src/components/letter-spacing-control/index.js +3 -2
- package/src/components/link-control/search-item.js +14 -0
- package/src/components/link-control/search-results.js +1 -0
- package/src/components/link-control/use-search-handler.js +22 -15
- package/src/components/resizable-box-popover/index.js +1 -1
- package/src/components/rich-text/index.js +1 -1
- package/src/components/spacing-sizes-control/hooks/use-spacing-sizes.js +7 -5
- package/src/components/spacing-sizes-control/input-controls/spacing-input-control.js +3 -2
- package/src/components/unit-control/index.js +3 -8
- package/src/components/use-block-commands/index.js +2 -1
- package/src/components/{use-setting → use-settings}/README.md +9 -10
- package/src/components/use-settings/index.js +272 -0
- package/src/components/{use-setting → use-settings}/test/index.js +47 -5
- package/src/hooks/align.js +79 -54
- package/src/hooks/anchor.js +75 -65
- package/src/hooks/background.js +7 -9
- package/src/hooks/color.js +7 -4
- package/src/hooks/duotone.js +24 -19
- package/src/hooks/font-size.js +4 -4
- package/src/hooks/layout.js +11 -11
- package/src/hooks/line-height.js +3 -3
- package/src/hooks/position.js +5 -3
- package/src/hooks/use-color-props.js +21 -14
- package/src/hooks/utils.js +88 -43
- package/src/layouts/constrained.js +3 -8
- package/src/utils/object.js +4 -1
- package/src/utils/test/__snapshots__/transform-styles.js.snap +103 -0
- package/src/utils/test/transform-styles.js +217 -0
- package/src/utils/transform-styles/index.js +25 -25
- package/build/components/use-setting/index.js +0 -161
- package/build/components/use-setting/index.js.map +0 -1
- package/build/utils/transform-styles/ast/index.js +0 -21
- package/build/utils/transform-styles/ast/index.js.map +0 -1
- package/build/utils/transform-styles/ast/parse.js +0 -660
- package/build/utils/transform-styles/ast/parse.js.map +0 -1
- package/build/utils/transform-styles/ast/stringify/compiler.js +0 -52
- package/build/utils/transform-styles/ast/stringify/compiler.js.map +0 -1
- package/build/utils/transform-styles/ast/stringify/compress.js +0 -178
- package/build/utils/transform-styles/ast/stringify/compress.js.map +0 -1
- package/build/utils/transform-styles/ast/stringify/identity.js +0 -207
- package/build/utils/transform-styles/ast/stringify/identity.js.map +0 -1
- package/build/utils/transform-styles/ast/stringify/index.js +0 -36
- package/build/utils/transform-styles/ast/stringify/index.js.map +0 -1
- package/build/utils/transform-styles/transforms/url-rewrite.js +0 -130
- package/build/utils/transform-styles/transforms/url-rewrite.js.map +0 -1
- package/build/utils/transform-styles/transforms/wrap.js +0 -59
- package/build/utils/transform-styles/transforms/wrap.js.map +0 -1
- package/build/utils/transform-styles/traverse.js +0 -37
- package/build/utils/transform-styles/traverse.js.map +0 -1
- package/build-module/components/use-setting/index.js +0 -154
- package/build-module/components/use-setting/index.js.map +0 -1
- package/build-module/utils/transform-styles/ast/index.js +0 -6
- package/build-module/utils/transform-styles/ast/index.js.map +0 -1
- package/build-module/utils/transform-styles/ast/parse.js +0 -654
- package/build-module/utils/transform-styles/ast/parse.js.map +0 -1
- package/build-module/utils/transform-styles/ast/stringify/compiler.js +0 -49
- package/build-module/utils/transform-styles/ast/stringify/compiler.js.map +0 -1
- package/build-module/utils/transform-styles/ast/stringify/compress.js +0 -176
- package/build-module/utils/transform-styles/ast/stringify/compress.js.map +0 -1
- package/build-module/utils/transform-styles/ast/stringify/identity.js +0 -206
- package/build-module/utils/transform-styles/ast/stringify/identity.js.map +0 -1
- package/build-module/utils/transform-styles/ast/stringify/index.js +0 -29
- package/build-module/utils/transform-styles/ast/stringify/index.js.map +0 -1
- package/build-module/utils/transform-styles/transforms/url-rewrite.js +0 -123
- package/build-module/utils/transform-styles/transforms/url-rewrite.js.map +0 -1
- package/build-module/utils/transform-styles/transforms/wrap.js +0 -52
- package/build-module/utils/transform-styles/transforms/wrap.js.map +0 -1
- package/build-module/utils/transform-styles/traverse.js +0 -28
- package/build-module/utils/transform-styles/traverse.js.map +0 -1
- package/src/components/use-setting/index.js +0 -218
- package/src/utils/transform-styles/ast/index.js +0 -5
- package/src/utils/transform-styles/ast/parse.js +0 -732
- package/src/utils/transform-styles/ast/stringify/compiler.js +0 -50
- package/src/utils/transform-styles/ast/stringify/compress.js +0 -238
- package/src/utils/transform-styles/ast/stringify/identity.js +0 -286
- package/src/utils/transform-styles/ast/stringify/index.js +0 -32
- package/src/utils/transform-styles/test/__snapshots__/traverse.js.snap +0 -7
- package/src/utils/transform-styles/test/traverse.js +0 -24
- package/src/utils/transform-styles/transforms/test/__snapshots__/url-rewrite.js.snap +0 -25
- package/src/utils/transform-styles/transforms/test/__snapshots__/wrap.js.snap +0 -64
- package/src/utils/transform-styles/transforms/test/url-rewrite.js +0 -39
- package/src/utils/transform-styles/transforms/test/wrap.js +0 -95
- package/src/utils/transform-styles/transforms/url-rewrite.js +0 -139
- package/src/utils/transform-styles/transforms/wrap.js +0 -56
- package/src/utils/transform-styles/traverse.js +0 -32
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
|
-
|
|
3
|
-
exports[`CSS selector wrap should ignore font-face selectors 1`] = `
|
|
4
|
-
"@font-face {
|
|
5
|
-
font-family: myFirstFont;
|
|
6
|
-
src: url(sansation_light.woff);
|
|
7
|
-
}"
|
|
8
|
-
`;
|
|
9
|
-
|
|
10
|
-
exports[`CSS selector wrap should ignore keyframes 1`] = `
|
|
11
|
-
"@keyframes edit-post__fade-in-animation {
|
|
12
|
-
from {
|
|
13
|
-
opacity: 0;
|
|
14
|
-
}
|
|
15
|
-
}"
|
|
16
|
-
`;
|
|
17
|
-
|
|
18
|
-
exports[`CSS selector wrap should ignore selectors 1`] = `
|
|
19
|
-
".my-namespace h1,
|
|
20
|
-
body {
|
|
21
|
-
color: red;
|
|
22
|
-
}"
|
|
23
|
-
`;
|
|
24
|
-
|
|
25
|
-
exports[`CSS selector wrap should not double wrap selectors 1`] = `
|
|
26
|
-
".my-namespace h1,
|
|
27
|
-
.my-namespace .red {
|
|
28
|
-
color: red;
|
|
29
|
-
}"
|
|
30
|
-
`;
|
|
31
|
-
|
|
32
|
-
exports[`CSS selector wrap should replace :root selectors 1`] = `
|
|
33
|
-
".my-namespace {
|
|
34
|
-
--my-color: #ff0000;
|
|
35
|
-
}"
|
|
36
|
-
`;
|
|
37
|
-
|
|
38
|
-
exports[`CSS selector wrap should replace root tags 1`] = `
|
|
39
|
-
".my-namespace,
|
|
40
|
-
.my-namespace h1 {
|
|
41
|
-
color: red;
|
|
42
|
-
}"
|
|
43
|
-
`;
|
|
44
|
-
|
|
45
|
-
exports[`CSS selector wrap should wrap multiple selectors 1`] = `
|
|
46
|
-
".my-namespace h1,
|
|
47
|
-
.my-namespace h2 {
|
|
48
|
-
color: red;
|
|
49
|
-
}"
|
|
50
|
-
`;
|
|
51
|
-
|
|
52
|
-
exports[`CSS selector wrap should wrap regular selectors 1`] = `
|
|
53
|
-
".my-namespace h1 {
|
|
54
|
-
color: red;
|
|
55
|
-
}"
|
|
56
|
-
`;
|
|
57
|
-
|
|
58
|
-
exports[`CSS selector wrap should wrap selectors inside container queries 1`] = `
|
|
59
|
-
"@container (width > 400px) {
|
|
60
|
-
.my-namespace h1 {
|
|
61
|
-
color: red;
|
|
62
|
-
}
|
|
63
|
-
}"
|
|
64
|
-
`;
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Internal dependencies
|
|
3
|
-
*/
|
|
4
|
-
import traverse from '../../traverse';
|
|
5
|
-
import rewrite from '../url-rewrite';
|
|
6
|
-
|
|
7
|
-
describe( 'URL rewrite', () => {
|
|
8
|
-
it( 'should replace relative paths', () => {
|
|
9
|
-
const callback = rewrite( 'http://wp-site.local/themes/gut/css/' );
|
|
10
|
-
const input = `h1 { background: url(images/test.png); }`;
|
|
11
|
-
const output = traverse( input, callback );
|
|
12
|
-
|
|
13
|
-
expect( output ).toMatchSnapshot();
|
|
14
|
-
} );
|
|
15
|
-
|
|
16
|
-
it( 'should replace complex relative paths', () => {
|
|
17
|
-
const callback = rewrite( 'http://wp-site.local/themes/gut/css/' );
|
|
18
|
-
const input = `h1 { background: url(../images/test.png); }`;
|
|
19
|
-
const output = traverse( input, callback );
|
|
20
|
-
|
|
21
|
-
expect( output ).toMatchSnapshot();
|
|
22
|
-
} );
|
|
23
|
-
|
|
24
|
-
it( 'should not replace absolute paths', () => {
|
|
25
|
-
const callback = rewrite( 'http://wp-site.local/themes/gut/css/' );
|
|
26
|
-
const input = `h1 { background: url(/images/test.png); }`;
|
|
27
|
-
const output = traverse( input, callback );
|
|
28
|
-
|
|
29
|
-
expect( output ).toMatchSnapshot();
|
|
30
|
-
} );
|
|
31
|
-
|
|
32
|
-
it( 'should not replace remote paths', () => {
|
|
33
|
-
const callback = rewrite( 'http://wp-site.local/themes/gut/css/' );
|
|
34
|
-
const input = `h1 { background: url(http://wp.org/images/test.png); }`;
|
|
35
|
-
const output = traverse( input, callback );
|
|
36
|
-
|
|
37
|
-
expect( output ).toMatchSnapshot();
|
|
38
|
-
} );
|
|
39
|
-
} );
|
|
@@ -1,95 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Internal dependencies
|
|
3
|
-
*/
|
|
4
|
-
import traverse from '../../traverse';
|
|
5
|
-
import wrap from '../wrap';
|
|
6
|
-
|
|
7
|
-
describe( 'CSS selector wrap', () => {
|
|
8
|
-
it( 'should wrap regular selectors', () => {
|
|
9
|
-
const callback = wrap( '.my-namespace' );
|
|
10
|
-
const input = `h1 { color: red; }`;
|
|
11
|
-
const output = traverse( input, callback );
|
|
12
|
-
|
|
13
|
-
expect( output ).toMatchSnapshot();
|
|
14
|
-
} );
|
|
15
|
-
|
|
16
|
-
it( 'should wrap multiple selectors', () => {
|
|
17
|
-
const callback = wrap( '.my-namespace' );
|
|
18
|
-
const input = `h1, h2 { color: red; }`;
|
|
19
|
-
const output = traverse( input, callback );
|
|
20
|
-
|
|
21
|
-
expect( output ).toMatchSnapshot();
|
|
22
|
-
} );
|
|
23
|
-
|
|
24
|
-
it( 'should ignore selectors', () => {
|
|
25
|
-
const callback = wrap( '.my-namespace', [ 'body' ] );
|
|
26
|
-
const input = `h1, body { color: red; }`;
|
|
27
|
-
const output = traverse( input, callback );
|
|
28
|
-
|
|
29
|
-
expect( output ).toMatchSnapshot();
|
|
30
|
-
} );
|
|
31
|
-
|
|
32
|
-
it( 'should replace root tags', () => {
|
|
33
|
-
const callback = wrap( '.my-namespace' );
|
|
34
|
-
const input = `body, h1 { color: red; }`;
|
|
35
|
-
const output = traverse( input, callback );
|
|
36
|
-
|
|
37
|
-
expect( output ).toMatchSnapshot();
|
|
38
|
-
} );
|
|
39
|
-
|
|
40
|
-
it( 'should ignore keyframes', () => {
|
|
41
|
-
const callback = wrap( '.my-namespace' );
|
|
42
|
-
const input = `
|
|
43
|
-
@keyframes edit-post__fade-in-animation {
|
|
44
|
-
from {
|
|
45
|
-
opacity: 0;
|
|
46
|
-
}
|
|
47
|
-
}`;
|
|
48
|
-
const output = traverse( input, callback );
|
|
49
|
-
|
|
50
|
-
expect( output ).toMatchSnapshot();
|
|
51
|
-
} );
|
|
52
|
-
|
|
53
|
-
it( 'should wrap selectors inside container queries', () => {
|
|
54
|
-
const callback = wrap( '.my-namespace' );
|
|
55
|
-
const input = `
|
|
56
|
-
@container (width > 400px) {
|
|
57
|
-
h1 { color: red; }
|
|
58
|
-
}`;
|
|
59
|
-
const output = traverse( input, callback );
|
|
60
|
-
|
|
61
|
-
expect( output ).toMatchSnapshot();
|
|
62
|
-
} );
|
|
63
|
-
|
|
64
|
-
it( 'should ignore font-face selectors', () => {
|
|
65
|
-
const callback = wrap( '.my-namespace' );
|
|
66
|
-
const input = `
|
|
67
|
-
@font-face {
|
|
68
|
-
font-family: myFirstFont;
|
|
69
|
-
src: url(sansation_light.woff);
|
|
70
|
-
}`;
|
|
71
|
-
const output = traverse( input, callback );
|
|
72
|
-
|
|
73
|
-
expect( output ).toMatchSnapshot();
|
|
74
|
-
} );
|
|
75
|
-
|
|
76
|
-
it( 'should replace :root selectors', () => {
|
|
77
|
-
const callback = wrap( '.my-namespace' );
|
|
78
|
-
const input = `
|
|
79
|
-
:root {
|
|
80
|
-
--my-color: #ff0000;
|
|
81
|
-
}`;
|
|
82
|
-
const output = traverse( input, callback );
|
|
83
|
-
|
|
84
|
-
expect( output ).toMatchSnapshot();
|
|
85
|
-
} );
|
|
86
|
-
|
|
87
|
-
it( 'should not double wrap selectors', () => {
|
|
88
|
-
const callback = wrap( '.my-namespace' );
|
|
89
|
-
const input = ` .my-namespace h1, .red { color: red; }`;
|
|
90
|
-
|
|
91
|
-
const output = traverse( input, callback );
|
|
92
|
-
|
|
93
|
-
expect( output ).toMatchSnapshot();
|
|
94
|
-
} );
|
|
95
|
-
} );
|
|
@@ -1,139 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Return `true` if the given path is http/https.
|
|
3
|
-
*
|
|
4
|
-
* @param {string} filePath path
|
|
5
|
-
*
|
|
6
|
-
* @return {boolean} is remote path.
|
|
7
|
-
*/
|
|
8
|
-
function isRemotePath( filePath ) {
|
|
9
|
-
return /^(?:https?:)?\/\//.test( filePath );
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Return `true` if the given filePath is an absolute url.
|
|
14
|
-
*
|
|
15
|
-
* @param {string} filePath path
|
|
16
|
-
*
|
|
17
|
-
* @return {boolean} is absolute path.
|
|
18
|
-
*/
|
|
19
|
-
function isAbsolutePath( filePath ) {
|
|
20
|
-
return /^\/(?!\/)/.test( filePath );
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* Whether or not the url should be inluded.
|
|
25
|
-
*
|
|
26
|
-
* @param {Object} meta url meta info
|
|
27
|
-
*
|
|
28
|
-
* @return {boolean} is valid.
|
|
29
|
-
*/
|
|
30
|
-
function isValidURL( meta ) {
|
|
31
|
-
// Ignore hashes or data uris.
|
|
32
|
-
if (
|
|
33
|
-
meta.value.indexOf( 'data:' ) === 0 ||
|
|
34
|
-
meta.value.indexOf( '#' ) === 0
|
|
35
|
-
) {
|
|
36
|
-
return false;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
if ( isAbsolutePath( meta.value ) ) {
|
|
40
|
-
return false;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
// Do not handle the http/https urls if `includeRemote` is false.
|
|
44
|
-
if ( isRemotePath( meta.value ) ) {
|
|
45
|
-
return false;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
return true;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* Get the absolute path of the url, relative to the basePath
|
|
53
|
-
*
|
|
54
|
-
* @param {string} str the url
|
|
55
|
-
* @param {string} baseURL base URL
|
|
56
|
-
*
|
|
57
|
-
* @return {string} the full path to the file
|
|
58
|
-
*/
|
|
59
|
-
function getResourcePath( str, baseURL ) {
|
|
60
|
-
return new URL( str, baseURL ).toString();
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
/**
|
|
64
|
-
* Process the single `url()` pattern
|
|
65
|
-
*
|
|
66
|
-
* @param {string} baseURL the base URL for relative URLs.
|
|
67
|
-
*
|
|
68
|
-
* @return {Promise} the Promise.
|
|
69
|
-
*/
|
|
70
|
-
function processURL( baseURL ) {
|
|
71
|
-
return ( meta ) => ( {
|
|
72
|
-
...meta,
|
|
73
|
-
newUrl:
|
|
74
|
-
'url(' +
|
|
75
|
-
meta.before +
|
|
76
|
-
meta.quote +
|
|
77
|
-
getResourcePath( meta.value, baseURL ) +
|
|
78
|
-
meta.quote +
|
|
79
|
-
meta.after +
|
|
80
|
-
')',
|
|
81
|
-
} );
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
/**
|
|
85
|
-
* Get all `url()`s, and return the meta info
|
|
86
|
-
*
|
|
87
|
-
* @param {string} value decl.value.
|
|
88
|
-
*
|
|
89
|
-
* @return {Array} the urls.
|
|
90
|
-
*/
|
|
91
|
-
function getURLs( value ) {
|
|
92
|
-
const reg = /url\((\s*)(['"]?)(.+?)\2(\s*)\)/g;
|
|
93
|
-
let match;
|
|
94
|
-
const URLs = [];
|
|
95
|
-
|
|
96
|
-
while ( ( match = reg.exec( value ) ) !== null ) {
|
|
97
|
-
const meta = {
|
|
98
|
-
source: match[ 0 ],
|
|
99
|
-
before: match[ 1 ],
|
|
100
|
-
quote: match[ 2 ],
|
|
101
|
-
value: match[ 3 ],
|
|
102
|
-
after: match[ 4 ],
|
|
103
|
-
};
|
|
104
|
-
if ( isValidURL( meta ) ) {
|
|
105
|
-
URLs.push( meta );
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
return URLs;
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
/**
|
|
112
|
-
* Replace the raw value's `url()` segment to the new value
|
|
113
|
-
*
|
|
114
|
-
* @param {string} raw the raw value.
|
|
115
|
-
* @param {Array} URLs the URLs to replace.
|
|
116
|
-
*
|
|
117
|
-
* @return {string} the new value.
|
|
118
|
-
*/
|
|
119
|
-
function replaceURLs( raw, URLs ) {
|
|
120
|
-
URLs.forEach( ( item ) => {
|
|
121
|
-
raw = raw.replace( item.source, item.newUrl );
|
|
122
|
-
} );
|
|
123
|
-
|
|
124
|
-
return raw;
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
const rewrite = ( rootURL ) => ( node ) => {
|
|
128
|
-
if ( node.type === 'declaration' ) {
|
|
129
|
-
const updatedURLs = getURLs( node.value ).map( processURL( rootURL ) );
|
|
130
|
-
return {
|
|
131
|
-
...node,
|
|
132
|
-
value: replaceURLs( node.value, updatedURLs ),
|
|
133
|
-
};
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
return node;
|
|
137
|
-
};
|
|
138
|
-
|
|
139
|
-
export default rewrite;
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @constant string IS_ROOT_TAG Regex to check if the selector is a root tag selector.
|
|
3
|
-
*/
|
|
4
|
-
const IS_ROOT_TAG = /^(body|html|:root).*$/;
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Creates a callback to modify selectors so they only apply within a certain
|
|
8
|
-
* namespace.
|
|
9
|
-
*
|
|
10
|
-
* @param {string} namespace Namespace to prefix selectors with.
|
|
11
|
-
* @param {string[]} ignore Selectors to not prefix.
|
|
12
|
-
*
|
|
13
|
-
* @return {(node: Object) => Object} Callback to wrap selectors.
|
|
14
|
-
*/
|
|
15
|
-
const wrap =
|
|
16
|
-
( namespace, ignore = [] ) =>
|
|
17
|
-
( node ) => {
|
|
18
|
-
/**
|
|
19
|
-
* Updates selector if necessary.
|
|
20
|
-
*
|
|
21
|
-
* @param {string} selector Selector to modify.
|
|
22
|
-
*
|
|
23
|
-
* @return {string} Updated selector.
|
|
24
|
-
*/
|
|
25
|
-
const updateSelector = ( selector ) => {
|
|
26
|
-
if ( ignore.includes( selector.trim() ) ) {
|
|
27
|
-
return selector;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
// Skip the update when a selector already has a namespace + space (" ").
|
|
31
|
-
if ( selector.trim().startsWith( `${ namespace } ` ) ) {
|
|
32
|
-
return selector;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
// Anything other than a root tag is always prefixed.
|
|
36
|
-
{
|
|
37
|
-
if ( ! selector.match( IS_ROOT_TAG ) ) {
|
|
38
|
-
return namespace + ' ' + selector;
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
// HTML and Body elements cannot be contained within our container so lets extract their styles.
|
|
43
|
-
return selector.replace( /^(body|html|:root)/, namespace );
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
if ( node.type === 'rule' ) {
|
|
47
|
-
return {
|
|
48
|
-
...node,
|
|
49
|
-
selectors: node.selectors.map( updateSelector ),
|
|
50
|
-
};
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
return node;
|
|
54
|
-
};
|
|
55
|
-
|
|
56
|
-
export default wrap;
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* External dependencies
|
|
3
|
-
*/
|
|
4
|
-
import traverse from 'traverse';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Internal dependencies
|
|
8
|
-
*/
|
|
9
|
-
import { parse, stringify } from './ast';
|
|
10
|
-
|
|
11
|
-
function traverseCSS( css, callback ) {
|
|
12
|
-
try {
|
|
13
|
-
const parsed = parse( css );
|
|
14
|
-
|
|
15
|
-
const updated = traverse.map( parsed, function ( node ) {
|
|
16
|
-
if ( ! node ) {
|
|
17
|
-
return node;
|
|
18
|
-
}
|
|
19
|
-
const updatedNode = callback( node );
|
|
20
|
-
return this.update( updatedNode );
|
|
21
|
-
} );
|
|
22
|
-
|
|
23
|
-
return stringify( updated );
|
|
24
|
-
} catch ( err ) {
|
|
25
|
-
// eslint-disable-next-line no-console
|
|
26
|
-
console.warn( 'Error while traversing the CSS: ' + err );
|
|
27
|
-
|
|
28
|
-
return null;
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
export default traverseCSS;
|