@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,660 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = _default;
|
|
7
|
-
/* eslint-disable @wordpress/no-unused-vars-before-return */
|
|
8
|
-
|
|
9
|
-
// Adapted from https://github.com/reworkcss/css
|
|
10
|
-
// because we needed to remove source map support.
|
|
11
|
-
|
|
12
|
-
// http://www.w3.org/TR/CSS21/grammar.htm
|
|
13
|
-
// https://github.com/visionmedia/css-parse/pull/49#issuecomment-30088027
|
|
14
|
-
const commentre = /\/\*[^*]*\*+([^/*][^*]*\*+)*\//g;
|
|
15
|
-
function _default(css, options) {
|
|
16
|
-
options = options || {};
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Positional.
|
|
20
|
-
*/
|
|
21
|
-
|
|
22
|
-
let lineno = 1;
|
|
23
|
-
let column = 1;
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* Update lineno and column based on `str`.
|
|
27
|
-
*/
|
|
28
|
-
|
|
29
|
-
function updatePosition(str) {
|
|
30
|
-
const lines = str.match(/\n/g);
|
|
31
|
-
if (lines) {
|
|
32
|
-
lineno += lines.length;
|
|
33
|
-
}
|
|
34
|
-
const i = str.lastIndexOf('\n');
|
|
35
|
-
// eslint-disable-next-line no-bitwise
|
|
36
|
-
column = ~i ? str.length - i : column + str.length;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* Mark position and patch `node.position`.
|
|
41
|
-
*/
|
|
42
|
-
|
|
43
|
-
function position() {
|
|
44
|
-
const start = {
|
|
45
|
-
line: lineno,
|
|
46
|
-
column
|
|
47
|
-
};
|
|
48
|
-
return function (node) {
|
|
49
|
-
node.position = new Position(start);
|
|
50
|
-
whitespace();
|
|
51
|
-
return node;
|
|
52
|
-
};
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
/**
|
|
56
|
-
* Store position information for a node
|
|
57
|
-
*/
|
|
58
|
-
|
|
59
|
-
function Position(start) {
|
|
60
|
-
this.start = start;
|
|
61
|
-
this.end = {
|
|
62
|
-
line: lineno,
|
|
63
|
-
column
|
|
64
|
-
};
|
|
65
|
-
this.source = options.source;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
/**
|
|
69
|
-
* Non-enumerable source string
|
|
70
|
-
*/
|
|
71
|
-
|
|
72
|
-
Position.prototype.content = css;
|
|
73
|
-
|
|
74
|
-
/**
|
|
75
|
-
* Error `msg`.
|
|
76
|
-
*/
|
|
77
|
-
|
|
78
|
-
const errorsList = [];
|
|
79
|
-
function error(msg) {
|
|
80
|
-
const err = new Error(options.source + ':' + lineno + ':' + column + ': ' + msg);
|
|
81
|
-
err.reason = msg;
|
|
82
|
-
err.filename = options.source;
|
|
83
|
-
err.line = lineno;
|
|
84
|
-
err.column = column;
|
|
85
|
-
err.source = css;
|
|
86
|
-
if (options.silent) {
|
|
87
|
-
errorsList.push(err);
|
|
88
|
-
} else {
|
|
89
|
-
throw err;
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
/**
|
|
94
|
-
* Parse stylesheet.
|
|
95
|
-
*/
|
|
96
|
-
|
|
97
|
-
function stylesheet() {
|
|
98
|
-
const rulesList = rules();
|
|
99
|
-
return {
|
|
100
|
-
type: 'stylesheet',
|
|
101
|
-
stylesheet: {
|
|
102
|
-
source: options.source,
|
|
103
|
-
rules: rulesList,
|
|
104
|
-
parsingErrors: errorsList
|
|
105
|
-
}
|
|
106
|
-
};
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
/**
|
|
110
|
-
* Opening brace.
|
|
111
|
-
*/
|
|
112
|
-
|
|
113
|
-
function open() {
|
|
114
|
-
return match(/^{\s*/);
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
/**
|
|
118
|
-
* Closing brace.
|
|
119
|
-
*/
|
|
120
|
-
|
|
121
|
-
function close() {
|
|
122
|
-
return match(/^}/);
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
/**
|
|
126
|
-
* Parse ruleset.
|
|
127
|
-
*/
|
|
128
|
-
|
|
129
|
-
function rules() {
|
|
130
|
-
let node;
|
|
131
|
-
const accumulator = [];
|
|
132
|
-
whitespace();
|
|
133
|
-
comments(accumulator);
|
|
134
|
-
while (css.length && css.charAt(0) !== '}' && (node = atrule() || rule())) {
|
|
135
|
-
if (node !== false) {
|
|
136
|
-
accumulator.push(node);
|
|
137
|
-
comments(accumulator);
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
return accumulator;
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
/**
|
|
144
|
-
* Match `re` and return captures.
|
|
145
|
-
*/
|
|
146
|
-
|
|
147
|
-
function match(re) {
|
|
148
|
-
const m = re.exec(css);
|
|
149
|
-
if (!m) {
|
|
150
|
-
return;
|
|
151
|
-
}
|
|
152
|
-
const str = m[0];
|
|
153
|
-
updatePosition(str);
|
|
154
|
-
css = css.slice(str.length);
|
|
155
|
-
return m;
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
/**
|
|
159
|
-
* Parse whitespace.
|
|
160
|
-
*/
|
|
161
|
-
|
|
162
|
-
function whitespace() {
|
|
163
|
-
match(/^\s*/);
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
/**
|
|
167
|
-
* Parse comments;
|
|
168
|
-
*/
|
|
169
|
-
|
|
170
|
-
function comments(accumulator) {
|
|
171
|
-
let c;
|
|
172
|
-
accumulator = accumulator || [];
|
|
173
|
-
// eslint-disable-next-line no-cond-assign
|
|
174
|
-
while (c = comment()) {
|
|
175
|
-
if (c !== false) {
|
|
176
|
-
accumulator.push(c);
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
return accumulator;
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
/**
|
|
183
|
-
* Parse comment.
|
|
184
|
-
*/
|
|
185
|
-
|
|
186
|
-
function comment() {
|
|
187
|
-
const pos = position();
|
|
188
|
-
if ('/' !== css.charAt(0) || '*' !== css.charAt(1)) {
|
|
189
|
-
return;
|
|
190
|
-
}
|
|
191
|
-
let i = 2;
|
|
192
|
-
while ('' !== css.charAt(i) && ('*' !== css.charAt(i) || '/' !== css.charAt(i + 1))) {
|
|
193
|
-
++i;
|
|
194
|
-
}
|
|
195
|
-
i += 2;
|
|
196
|
-
if ('' === css.charAt(i - 1)) {
|
|
197
|
-
return error('End of comment missing');
|
|
198
|
-
}
|
|
199
|
-
const str = css.slice(2, i - 2);
|
|
200
|
-
column += 2;
|
|
201
|
-
updatePosition(str);
|
|
202
|
-
css = css.slice(i);
|
|
203
|
-
column += 2;
|
|
204
|
-
return pos({
|
|
205
|
-
type: 'comment',
|
|
206
|
-
comment: str
|
|
207
|
-
});
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
/**
|
|
211
|
-
* Parse selector.
|
|
212
|
-
*/
|
|
213
|
-
|
|
214
|
-
function selector() {
|
|
215
|
-
const m = match(/^([^{]+)/);
|
|
216
|
-
if (!m) {
|
|
217
|
-
return;
|
|
218
|
-
}
|
|
219
|
-
// FIXME: Remove all comments from selectors http://ostermiller.org/findcomment.html
|
|
220
|
-
return trim(m[0]).replace(/\/\*([^*]|[\r\n]|(\*+([^*/]|[\r\n])))*\*\/+/g, '').replace(/"(?:\\"|[^"])*"|'(?:\\'|[^'])*'/g, function (matched) {
|
|
221
|
-
return matched.replace(/,/g, '\u200C');
|
|
222
|
-
}).split(/\s*(?![^(]*\)),\s*/).map(function (s) {
|
|
223
|
-
return s.replace(/\u200C/g, ',');
|
|
224
|
-
});
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
/**
|
|
228
|
-
* Parse declaration.
|
|
229
|
-
*/
|
|
230
|
-
|
|
231
|
-
function declaration() {
|
|
232
|
-
const pos = position();
|
|
233
|
-
|
|
234
|
-
// prop.
|
|
235
|
-
let prop = match(/^(\*?[-#\/\*\\\w]+(\[[0-9a-z_-]+\])?)\s*/);
|
|
236
|
-
if (!prop) {
|
|
237
|
-
return;
|
|
238
|
-
}
|
|
239
|
-
prop = trim(prop[0]);
|
|
240
|
-
|
|
241
|
-
// :
|
|
242
|
-
if (!match(/^:\s*/)) {
|
|
243
|
-
return error("property missing ':'");
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
// val.
|
|
247
|
-
const val = match(/^((?:'(?:\\'|.)*?'|"(?:\\"|.)*?"|\([^\)]*?\)|[^};])+)/);
|
|
248
|
-
const ret = pos({
|
|
249
|
-
type: 'declaration',
|
|
250
|
-
property: prop.replace(commentre, ''),
|
|
251
|
-
value: val ? trim(val[0]).replace(commentre, '') : ''
|
|
252
|
-
});
|
|
253
|
-
|
|
254
|
-
// ;
|
|
255
|
-
match(/^[;\s]*/);
|
|
256
|
-
return ret;
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
/**
|
|
260
|
-
* Parse declarations.
|
|
261
|
-
*/
|
|
262
|
-
|
|
263
|
-
function declarations() {
|
|
264
|
-
const decls = [];
|
|
265
|
-
if (!open()) {
|
|
266
|
-
return error("missing '{'");
|
|
267
|
-
}
|
|
268
|
-
comments(decls);
|
|
269
|
-
|
|
270
|
-
// declarations.
|
|
271
|
-
let decl;
|
|
272
|
-
// eslint-disable-next-line no-cond-assign
|
|
273
|
-
while (decl = declaration()) {
|
|
274
|
-
if (decl !== false) {
|
|
275
|
-
decls.push(decl);
|
|
276
|
-
comments(decls);
|
|
277
|
-
}
|
|
278
|
-
}
|
|
279
|
-
if (!close()) {
|
|
280
|
-
return error("missing '}'");
|
|
281
|
-
}
|
|
282
|
-
return decls;
|
|
283
|
-
}
|
|
284
|
-
|
|
285
|
-
/**
|
|
286
|
-
* Parse keyframe.
|
|
287
|
-
*/
|
|
288
|
-
|
|
289
|
-
function keyframe() {
|
|
290
|
-
let m;
|
|
291
|
-
const vals = [];
|
|
292
|
-
const pos = position();
|
|
293
|
-
|
|
294
|
-
// eslint-disable-next-line no-cond-assign
|
|
295
|
-
while (m = match(/^((\d+\.\d+|\.\d+|\d+)%?|[a-z]+)\s*/)) {
|
|
296
|
-
vals.push(m[1]);
|
|
297
|
-
match(/^,\s*/);
|
|
298
|
-
}
|
|
299
|
-
if (!vals.length) {
|
|
300
|
-
return;
|
|
301
|
-
}
|
|
302
|
-
return pos({
|
|
303
|
-
type: 'keyframe',
|
|
304
|
-
values: vals,
|
|
305
|
-
declarations: declarations()
|
|
306
|
-
});
|
|
307
|
-
}
|
|
308
|
-
|
|
309
|
-
/**
|
|
310
|
-
* Parse keyframes.
|
|
311
|
-
*/
|
|
312
|
-
|
|
313
|
-
function atkeyframes() {
|
|
314
|
-
const pos = position();
|
|
315
|
-
let m = match(/^@([-\w]+)?keyframes\s*/);
|
|
316
|
-
if (!m) {
|
|
317
|
-
return;
|
|
318
|
-
}
|
|
319
|
-
const vendor = m[1];
|
|
320
|
-
|
|
321
|
-
// identifier
|
|
322
|
-
m = match(/^([-\w]+)\s*/);
|
|
323
|
-
if (!m) {
|
|
324
|
-
return error('@keyframes missing name');
|
|
325
|
-
}
|
|
326
|
-
const name = m[1];
|
|
327
|
-
if (!open()) {
|
|
328
|
-
return error("@keyframes missing '{'");
|
|
329
|
-
}
|
|
330
|
-
let frame;
|
|
331
|
-
let frames = comments();
|
|
332
|
-
// eslint-disable-next-line no-cond-assign
|
|
333
|
-
while (frame = keyframe()) {
|
|
334
|
-
frames.push(frame);
|
|
335
|
-
frames = frames.concat(comments());
|
|
336
|
-
}
|
|
337
|
-
if (!close()) {
|
|
338
|
-
return error("@keyframes missing '}'");
|
|
339
|
-
}
|
|
340
|
-
return pos({
|
|
341
|
-
type: 'keyframes',
|
|
342
|
-
name,
|
|
343
|
-
vendor,
|
|
344
|
-
keyframes: frames
|
|
345
|
-
});
|
|
346
|
-
}
|
|
347
|
-
|
|
348
|
-
/**
|
|
349
|
-
* Parse supports.
|
|
350
|
-
*/
|
|
351
|
-
|
|
352
|
-
function atsupports() {
|
|
353
|
-
const pos = position();
|
|
354
|
-
const m = match(/^@supports *([^{]+)/);
|
|
355
|
-
if (!m) {
|
|
356
|
-
return;
|
|
357
|
-
}
|
|
358
|
-
const supports = trim(m[1]);
|
|
359
|
-
if (!open()) {
|
|
360
|
-
return error("@supports missing '{'");
|
|
361
|
-
}
|
|
362
|
-
const style = comments().concat(rules());
|
|
363
|
-
if (!close()) {
|
|
364
|
-
return error("@supports missing '}'");
|
|
365
|
-
}
|
|
366
|
-
return pos({
|
|
367
|
-
type: 'supports',
|
|
368
|
-
supports,
|
|
369
|
-
rules: style
|
|
370
|
-
});
|
|
371
|
-
}
|
|
372
|
-
|
|
373
|
-
/**
|
|
374
|
-
* Parse host.
|
|
375
|
-
*/
|
|
376
|
-
|
|
377
|
-
function athost() {
|
|
378
|
-
const pos = position();
|
|
379
|
-
const m = match(/^@host\s*/);
|
|
380
|
-
if (!m) {
|
|
381
|
-
return;
|
|
382
|
-
}
|
|
383
|
-
if (!open()) {
|
|
384
|
-
return error("@host missing '{'");
|
|
385
|
-
}
|
|
386
|
-
const style = comments().concat(rules());
|
|
387
|
-
if (!close()) {
|
|
388
|
-
return error("@host missing '}'");
|
|
389
|
-
}
|
|
390
|
-
return pos({
|
|
391
|
-
type: 'host',
|
|
392
|
-
rules: style
|
|
393
|
-
});
|
|
394
|
-
}
|
|
395
|
-
|
|
396
|
-
/**
|
|
397
|
-
* Parse media.
|
|
398
|
-
*/
|
|
399
|
-
|
|
400
|
-
function atmedia() {
|
|
401
|
-
const pos = position();
|
|
402
|
-
const m = match(/^@media *([^{]+)/);
|
|
403
|
-
if (!m) {
|
|
404
|
-
return;
|
|
405
|
-
}
|
|
406
|
-
const media = trim(m[1]);
|
|
407
|
-
if (!open()) {
|
|
408
|
-
return error("@media missing '{'");
|
|
409
|
-
}
|
|
410
|
-
const style = comments().concat(rules());
|
|
411
|
-
if (!close()) {
|
|
412
|
-
return error("@media missing '}'");
|
|
413
|
-
}
|
|
414
|
-
return pos({
|
|
415
|
-
type: 'media',
|
|
416
|
-
media,
|
|
417
|
-
rules: style
|
|
418
|
-
});
|
|
419
|
-
}
|
|
420
|
-
|
|
421
|
-
/**
|
|
422
|
-
* Parse container.
|
|
423
|
-
*/
|
|
424
|
-
|
|
425
|
-
function atcontainer() {
|
|
426
|
-
const pos = position();
|
|
427
|
-
const m = match(/^@container *([^{]+)/);
|
|
428
|
-
if (!m) {
|
|
429
|
-
return;
|
|
430
|
-
}
|
|
431
|
-
const container = trim(m[1]);
|
|
432
|
-
if (!open()) {
|
|
433
|
-
return error("@container missing '{'");
|
|
434
|
-
}
|
|
435
|
-
const style = comments().concat(rules());
|
|
436
|
-
if (!close()) {
|
|
437
|
-
return error("@container missing '}'");
|
|
438
|
-
}
|
|
439
|
-
return pos({
|
|
440
|
-
type: 'container',
|
|
441
|
-
container,
|
|
442
|
-
rules: style
|
|
443
|
-
});
|
|
444
|
-
}
|
|
445
|
-
|
|
446
|
-
/**
|
|
447
|
-
* Parse custom-media.
|
|
448
|
-
*/
|
|
449
|
-
|
|
450
|
-
function atcustommedia() {
|
|
451
|
-
const pos = position();
|
|
452
|
-
const m = match(/^@custom-media\s+(--[^\s]+)\s*([^{;]+);/);
|
|
453
|
-
if (!m) {
|
|
454
|
-
return;
|
|
455
|
-
}
|
|
456
|
-
return pos({
|
|
457
|
-
type: 'custom-media',
|
|
458
|
-
name: trim(m[1]),
|
|
459
|
-
media: trim(m[2])
|
|
460
|
-
});
|
|
461
|
-
}
|
|
462
|
-
|
|
463
|
-
/**
|
|
464
|
-
* Parse paged media.
|
|
465
|
-
*/
|
|
466
|
-
|
|
467
|
-
function atpage() {
|
|
468
|
-
const pos = position();
|
|
469
|
-
const m = match(/^@page */);
|
|
470
|
-
if (!m) {
|
|
471
|
-
return;
|
|
472
|
-
}
|
|
473
|
-
const sel = selector() || [];
|
|
474
|
-
if (!open()) {
|
|
475
|
-
return error("@page missing '{'");
|
|
476
|
-
}
|
|
477
|
-
let decls = comments();
|
|
478
|
-
|
|
479
|
-
// declarations.
|
|
480
|
-
let decl;
|
|
481
|
-
// eslint-disable-next-line no-cond-assign
|
|
482
|
-
while (decl = declaration()) {
|
|
483
|
-
decls.push(decl);
|
|
484
|
-
decls = decls.concat(comments());
|
|
485
|
-
}
|
|
486
|
-
if (!close()) {
|
|
487
|
-
return error("@page missing '}'");
|
|
488
|
-
}
|
|
489
|
-
return pos({
|
|
490
|
-
type: 'page',
|
|
491
|
-
selectors: sel,
|
|
492
|
-
declarations: decls
|
|
493
|
-
});
|
|
494
|
-
}
|
|
495
|
-
|
|
496
|
-
/**
|
|
497
|
-
* Parse document.
|
|
498
|
-
*/
|
|
499
|
-
|
|
500
|
-
function atdocument() {
|
|
501
|
-
const pos = position();
|
|
502
|
-
const m = match(/^@([-\w]+)?document *([^{]+)/);
|
|
503
|
-
if (!m) {
|
|
504
|
-
return;
|
|
505
|
-
}
|
|
506
|
-
const vendor = trim(m[1]);
|
|
507
|
-
const doc = trim(m[2]);
|
|
508
|
-
if (!open()) {
|
|
509
|
-
return error("@document missing '{'");
|
|
510
|
-
}
|
|
511
|
-
const style = comments().concat(rules());
|
|
512
|
-
if (!close()) {
|
|
513
|
-
return error("@document missing '}'");
|
|
514
|
-
}
|
|
515
|
-
return pos({
|
|
516
|
-
type: 'document',
|
|
517
|
-
document: doc,
|
|
518
|
-
vendor,
|
|
519
|
-
rules: style
|
|
520
|
-
});
|
|
521
|
-
}
|
|
522
|
-
|
|
523
|
-
/**
|
|
524
|
-
* Parse font-face.
|
|
525
|
-
*/
|
|
526
|
-
|
|
527
|
-
function atfontface() {
|
|
528
|
-
const pos = position();
|
|
529
|
-
const m = match(/^@font-face\s*/);
|
|
530
|
-
if (!m) {
|
|
531
|
-
return;
|
|
532
|
-
}
|
|
533
|
-
if (!open()) {
|
|
534
|
-
return error("@font-face missing '{'");
|
|
535
|
-
}
|
|
536
|
-
let decls = comments();
|
|
537
|
-
|
|
538
|
-
// declarations.
|
|
539
|
-
let decl;
|
|
540
|
-
// eslint-disable-next-line no-cond-assign
|
|
541
|
-
while (decl = declaration()) {
|
|
542
|
-
decls.push(decl);
|
|
543
|
-
decls = decls.concat(comments());
|
|
544
|
-
}
|
|
545
|
-
if (!close()) {
|
|
546
|
-
return error("@font-face missing '}'");
|
|
547
|
-
}
|
|
548
|
-
return pos({
|
|
549
|
-
type: 'font-face',
|
|
550
|
-
declarations: decls
|
|
551
|
-
});
|
|
552
|
-
}
|
|
553
|
-
|
|
554
|
-
/**
|
|
555
|
-
* Parse import
|
|
556
|
-
*/
|
|
557
|
-
|
|
558
|
-
const atimport = _compileAtrule('import');
|
|
559
|
-
|
|
560
|
-
/**
|
|
561
|
-
* Parse charset
|
|
562
|
-
*/
|
|
563
|
-
|
|
564
|
-
const atcharset = _compileAtrule('charset');
|
|
565
|
-
|
|
566
|
-
/**
|
|
567
|
-
* Parse namespace
|
|
568
|
-
*/
|
|
569
|
-
|
|
570
|
-
const atnamespace = _compileAtrule('namespace');
|
|
571
|
-
|
|
572
|
-
/**
|
|
573
|
-
* Parse non-block at-rules
|
|
574
|
-
*/
|
|
575
|
-
|
|
576
|
-
function _compileAtrule(name) {
|
|
577
|
-
const re = new RegExp('^@' + name + '\\s*([^;]+);');
|
|
578
|
-
return function () {
|
|
579
|
-
const pos = position();
|
|
580
|
-
const m = match(re);
|
|
581
|
-
if (!m) {
|
|
582
|
-
return;
|
|
583
|
-
}
|
|
584
|
-
const ret = {
|
|
585
|
-
type: name
|
|
586
|
-
};
|
|
587
|
-
ret[name] = m[1].trim();
|
|
588
|
-
return pos(ret);
|
|
589
|
-
};
|
|
590
|
-
}
|
|
591
|
-
|
|
592
|
-
/**
|
|
593
|
-
* Parse at rule.
|
|
594
|
-
*/
|
|
595
|
-
|
|
596
|
-
function atrule() {
|
|
597
|
-
if (css[0] !== '@') {
|
|
598
|
-
return;
|
|
599
|
-
}
|
|
600
|
-
return atkeyframes() || atmedia() || atcontainer() || atcustommedia() || atsupports() || atimport() || atcharset() || atnamespace() || atdocument() || atpage() || athost() || atfontface();
|
|
601
|
-
}
|
|
602
|
-
|
|
603
|
-
/**
|
|
604
|
-
* Parse rule.
|
|
605
|
-
*/
|
|
606
|
-
|
|
607
|
-
function rule() {
|
|
608
|
-
const pos = position();
|
|
609
|
-
const sel = selector();
|
|
610
|
-
if (!sel) {
|
|
611
|
-
return error('selector missing');
|
|
612
|
-
}
|
|
613
|
-
comments();
|
|
614
|
-
return pos({
|
|
615
|
-
type: 'rule',
|
|
616
|
-
selectors: sel,
|
|
617
|
-
declarations: declarations()
|
|
618
|
-
});
|
|
619
|
-
}
|
|
620
|
-
return addParent(stylesheet());
|
|
621
|
-
}
|
|
622
|
-
|
|
623
|
-
/**
|
|
624
|
-
* Trim `str`.
|
|
625
|
-
*/
|
|
626
|
-
|
|
627
|
-
function trim(str) {
|
|
628
|
-
return str ? str.replace(/^\s+|\s+$/g, '') : '';
|
|
629
|
-
}
|
|
630
|
-
|
|
631
|
-
/**
|
|
632
|
-
* Adds non-enumerable parent node reference to each node.
|
|
633
|
-
*/
|
|
634
|
-
|
|
635
|
-
function addParent(obj, parent) {
|
|
636
|
-
const isNode = obj && typeof obj.type === 'string';
|
|
637
|
-
const childParent = isNode ? obj : parent;
|
|
638
|
-
for (const k in obj) {
|
|
639
|
-
const value = obj[k];
|
|
640
|
-
if (Array.isArray(value)) {
|
|
641
|
-
value.forEach(function (v) {
|
|
642
|
-
addParent(v, childParent);
|
|
643
|
-
});
|
|
644
|
-
} else if (value && typeof value === 'object') {
|
|
645
|
-
addParent(value, childParent);
|
|
646
|
-
}
|
|
647
|
-
}
|
|
648
|
-
if (isNode) {
|
|
649
|
-
Object.defineProperty(obj, 'parent', {
|
|
650
|
-
configurable: true,
|
|
651
|
-
writable: true,
|
|
652
|
-
enumerable: false,
|
|
653
|
-
value: parent || null
|
|
654
|
-
});
|
|
655
|
-
}
|
|
656
|
-
return obj;
|
|
657
|
-
}
|
|
658
|
-
|
|
659
|
-
/* eslint-enable @wordpress/no-unused-vars-before-return */
|
|
660
|
-
//# sourceMappingURL=parse.js.map
|