@wordpress/style-engine 0.9.0 → 0.12.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 +6 -0
- package/README.md +38 -6
- package/build/styles/border/index.js +94 -0
- package/build/styles/border/index.js.map +1 -0
- package/build/styles/index.js +3 -1
- package/build/styles/index.js.map +1 -1
- package/build/styles/spacing/margin.js +4 -1
- package/build/styles/spacing/margin.js.map +1 -1
- package/build/styles/spacing/padding.js +4 -1
- package/build/styles/spacing/padding.js.map +1 -1
- package/build/styles/utils.js +26 -10
- package/build/styles/utils.js.map +1 -1
- package/build-module/styles/border/index.js +85 -0
- package/build-module/styles/border/index.js.map +1 -0
- package/build-module/styles/index.js +2 -1
- package/build-module/styles/index.js.map +1 -1
- package/build-module/styles/spacing/margin.js +4 -1
- package/build-module/styles/spacing/margin.js.map +1 -1
- package/build-module/styles/spacing/padding.js +4 -1
- package/build-module/styles/spacing/padding.js.map +1 -1
- package/build-module/styles/utils.js +25 -11
- package/build-module/styles/utils.js.map +1 -1
- package/build-types/styles/border/index.d.ts +10 -0
- package/build-types/styles/border/index.d.ts.map +1 -0
- package/build-types/styles/index.d.ts +3 -7
- package/build-types/styles/index.d.ts.map +1 -1
- package/build-types/styles/spacing/margin.d.ts.map +1 -1
- package/build-types/styles/spacing/padding.d.ts.map +1 -1
- package/build-types/styles/utils.d.ts +16 -7
- package/build-types/styles/utils.d.ts.map +1 -1
- package/build-types/types.d.ts +26 -1
- package/build-types/types.d.ts.map +1 -1
- package/class-wp-style-engine-css-declarations.php +119 -0
- package/class-wp-style-engine.php +322 -108
- package/package.json +2 -2
- package/phpunit/class-wp-style-engine-css-declarations-test.php +108 -0
- package/phpunit/class-wp-style-engine-test.php +296 -12
- package/src/styles/border/index.ts +145 -0
- package/src/styles/index.ts +7 -1
- package/src/styles/spacing/margin.ts +4 -6
- package/src/styles/spacing/padding.ts +4 -6
- package/src/styles/utils.ts +36 -12
- package/src/test/index.js +51 -0
- package/src/test/utils.js +12 -0
- package/src/types.ts +33 -1
- package/tsconfig.tsbuildinfo +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/style-engine/src/styles/utils.ts"],"names":["get","
|
|
1
|
+
{"version":3,"sources":["@wordpress/style-engine/src/styles/utils.ts"],"names":["get","VARIABLE_REFERENCE_PREFIX","VARIABLE_PATH_SEPARATOR_TOKEN_ATTRIBUTE","VARIABLE_PATH_SEPARATOR_TOKEN_STYLE","generateRule","style","options","path","ruleKey","styleValue","selector","key","value","getCSSVarFromStyleValue","generateBoxRules","ruleKeys","individualProperties","boxStyle","rules","push","default","sideRules","reduce","acc","side","individual","replace","upperFirst","startsWith","variable","slice","length","split","join","firstLetter","rest","toUpperCase"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,GAAT,QAAoB,QAApB;AAEA;AACA;AACA;;AAQA,SACCC,yBADD,EAECC,uCAFD,EAGCC,mCAHD,QAIO,aAJP;AAMA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASC,YAAT,CACNC,KADM,EAENC,OAFM,EAGNC,IAHM,EAINC,OAJM,EAKL;AACD,QAAMC,UAA8B,GAAGT,GAAG,CAAEK,KAAF,EAASE,IAAT,CAA1C;AAEA,SAAOE,UAAU,GACd,CACA;AACCC,IAAAA,QAAQ,EAAEJ,OAAF,aAAEA,OAAF,uBAAEA,OAAO,CAAEI,QADpB;AAECC,IAAAA,GAAG,EAAEH,OAFN;AAGCI,IAAAA,KAAK,EAAEC,uBAAuB,CAAEJ,UAAF;AAH/B,GADA,CADc,GAQd,EARH;AASA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASK,gBAAT,CACNT,KADM,EAENC,OAFM,EAGNC,IAHM,EAINQ,QAJM,EAMe;AAAA,MADrBC,oBACqB,uEADY,CAAE,KAAF,EAAS,OAAT,EAAkB,QAAlB,EAA4B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B3B,yBAAvB,CAFD,EAGE;AACD,UAAM4B,QAAQ,GAAGpB,UAAU,CACzBqB,KADe,CACR7B,yBAAyB,CAAC8B,MADlB,EAEfC,KAFe,CAER9B,uCAFQ,EAGf+B,IAHe,CAGT9B,mCAHS,CAAjB;AAIA,WAAQ,aAAa0B,QAAU,GAA/B;AACA;;AACD,SAAOpB,UAAP;AACA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASkB,UAAT,OAAwD;AAAA,MAAnC,CAAEO,WAAF,EAAe,GAAGC,IAAlB,CAAmC;AAC9D,SAAOD,WAAW,CAACE,WAAZ,KAA4BD,IAAI,CAACF,IAAL,CAAW,EAAX,CAAnC;AACA","sourcesContent":["/**\n * External dependencies\n */\nimport { get } from 'lodash';\n\n/**\n * Internal dependencies\n */\nimport type {\n\tCssRulesKeys,\n\tGeneratedCSSRule,\n\tStyle,\n\tBox,\n\tStyleOptions,\n} from '../types';\nimport {\n\tVARIABLE_REFERENCE_PREFIX,\n\tVARIABLE_PATH_SEPARATOR_TOKEN_ATTRIBUTE,\n\tVARIABLE_PATH_SEPARATOR_TOKEN_STYLE,\n} from './constants';\n\n/**\n * Returns a JSON representation of the generated CSS rules.\n *\n * @param style Style object.\n * @param options Options object with settings to adjust how the styles are generated.\n * @param path An array of strings representing the path to the style value in the style object.\n * @param ruleKey A CSS property key.\n *\n * @return GeneratedCSSRule[] CSS rules.\n */\nexport function generateRule(\n\tstyle: Style,\n\toptions: StyleOptions,\n\tpath: string[],\n\truleKey: string\n) {\n\tconst styleValue: string | undefined = get( style, path );\n\n\treturn styleValue\n\t\t? [\n\t\t\t\t{\n\t\t\t\t\tselector: options?.selector,\n\t\t\t\t\tkey: ruleKey,\n\t\t\t\t\tvalue: getCSSVarFromStyleValue( styleValue ),\n\t\t\t\t},\n\t\t ]\n\t\t: [];\n}\n\n/**\n * Returns a JSON representation of the generated CSS rules taking into account box model properties, top, right, bottom, left.\n *\n * @param style Style object.\n * @param options Options object with settings to adjust how the styles are generated.\n * @param path An array of strings representing the path to the style value in the style object.\n * @param ruleKeys An array of CSS property keys and patterns.\n * @param individualProperties The \"sides\" or individual properties for which to generate rules.\n *\n * @return GeneratedCSSRule[] CSS rules.\n */\nexport function generateBoxRules(\n\tstyle: Style,\n\toptions: StyleOptions,\n\tpath: string[],\n\truleKeys: CssRulesKeys,\n\tindividualProperties: string[] = [ 'top', 'right', 'bottom', 'left' ]\n): GeneratedCSSRule[] {\n\tconst boxStyle: Box | string | undefined = get( style, path );\n\tif ( ! boxStyle ) {\n\t\treturn [];\n\t}\n\n\tconst rules: GeneratedCSSRule[] = [];\n\tif ( typeof boxStyle === 'string' ) {\n\t\trules.push( {\n\t\t\tselector: options?.selector,\n\t\t\tkey: ruleKeys.default,\n\t\t\tvalue: boxStyle,\n\t\t} );\n\t} else {\n\t\tconst sideRules = individualProperties.reduce(\n\t\t\t( acc: GeneratedCSSRule[], side: string ) => {\n\t\t\t\tconst value: string | undefined = getCSSVarFromStyleValue(\n\t\t\t\t\tget( boxStyle, [ side ] )\n\t\t\t\t);\n\t\t\t\tif ( value ) {\n\t\t\t\t\tacc.push( {\n\t\t\t\t\t\tselector: options?.selector,\n\t\t\t\t\t\tkey: ruleKeys?.individual.replace(\n\t\t\t\t\t\t\t'%s',\n\t\t\t\t\t\t\tupperFirst( side )\n\t\t\t\t\t\t),\n\t\t\t\t\t\tvalue,\n\t\t\t\t\t} );\n\t\t\t\t}\n\t\t\t\treturn acc;\n\t\t\t},\n\t\t\t[]\n\t\t);\n\t\trules.push( ...sideRules );\n\t}\n\n\treturn rules;\n}\n\n/**\n * Returns a CSS var value from incoming style value following the pattern `var:description|context|slug`.\n *\n * @param styleValue A raw style value.\n *\n * @return string A CSS var value.\n */\nexport function getCSSVarFromStyleValue( styleValue: string ): string {\n\tif (\n\t\ttypeof styleValue === 'string' &&\n\t\tstyleValue.startsWith( VARIABLE_REFERENCE_PREFIX )\n\t) {\n\t\tconst variable = styleValue\n\t\t\t.slice( VARIABLE_REFERENCE_PREFIX.length )\n\t\t\t.split( VARIABLE_PATH_SEPARATOR_TOKEN_ATTRIBUTE )\n\t\t\t.join( VARIABLE_PATH_SEPARATOR_TOKEN_STYLE );\n\t\treturn `var(--wp--${ variable })`;\n\t}\n\treturn styleValue;\n}\n\n/**\n * Capitalizes the first letter in a string.\n *\n * @param {string} str The string whose first letter the function will capitalize.\n *\n * @return string A CSS var value.\n */\nexport function upperFirst( [ firstLetter, ...rest ]: string ) {\n\treturn firstLetter.toUpperCase() + rest.join( '' );\n}\n"]}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Internal dependencies
|
|
3
|
+
*/
|
|
4
|
+
import type { GeneratedCSSRule, Style, StyleDefinition, StyleOptions } from '../../types';
|
|
5
|
+
declare const _default: (StyleDefinition | {
|
|
6
|
+
name: string;
|
|
7
|
+
generate: (style: Style, options: StyleOptions) => GeneratedCSSRule[];
|
|
8
|
+
})[];
|
|
9
|
+
export default _default;
|
|
10
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/styles/border/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,KAAK,EAGX,gBAAgB,EAChB,KAAK,EACL,eAAe,EACf,YAAY,EACZ,MAAM,aAAa,CAAC;;;;;AA+HrB,wBAOE"}
|
|
@@ -1,9 +1,5 @@
|
|
|
1
|
-
export declare const styleDefinitions: {
|
|
1
|
+
export declare const styleDefinitions: (import("../types").StyleDefinition | {
|
|
2
2
|
name: string;
|
|
3
|
-
generate: (style: import("../types").Style, options: import("../types").StyleOptions) =>
|
|
4
|
-
|
|
5
|
-
key: string;
|
|
6
|
-
value: string;
|
|
7
|
-
}[];
|
|
8
|
-
}[];
|
|
3
|
+
generate: (style: import("../types").Style, options: import("../types").StyleOptions) => import("../types").GeneratedCSSRule[];
|
|
4
|
+
})[];
|
|
9
5
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/styles/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/styles/index.ts"],"names":[],"mappings":"AAQA,eAAO,MAAM,gBAAgB;;;IAK5B,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"margin.d.ts","sourceRoot":"","sources":["../../../src/styles/spacing/margin.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,KAAK,EAAE,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAGvD,QAAA,MAAM,MAAM;;sBAEQ,KAAK,WAAW,YAAY;
|
|
1
|
+
{"version":3,"file":"margin.d.ts","sourceRoot":"","sources":["../../../src/styles/spacing/margin.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,KAAK,EAAE,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAGvD,QAAA,MAAM,MAAM;;sBAEQ,KAAK,WAAW,YAAY;CAM/C,CAAC;AAEF,eAAe,MAAM,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"padding.d.ts","sourceRoot":"","sources":["../../../src/styles/spacing/padding.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,KAAK,EAAE,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAGvD,QAAA,MAAM,OAAO;;sBAEO,KAAK,WAAW,YAAY;
|
|
1
|
+
{"version":3,"file":"padding.d.ts","sourceRoot":"","sources":["../../../src/styles/spacing/padding.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,KAAK,EAAE,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAGvD,QAAA,MAAM,OAAO;;sBAEO,KAAK,WAAW,YAAY;CAM/C,CAAC;AAEF,eAAe,OAAO,CAAC"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Internal dependencies
|
|
3
3
|
*/
|
|
4
|
-
import type { GeneratedCSSRule, Style, StyleOptions } from '../types';
|
|
4
|
+
import type { CssRulesKeys, GeneratedCSSRule, Style, StyleOptions } from '../types';
|
|
5
5
|
/**
|
|
6
6
|
* Returns a JSON representation of the generated CSS rules.
|
|
7
7
|
*
|
|
@@ -20,14 +20,15 @@ export declare function generateRule(style: Style, options: StyleOptions, path:
|
|
|
20
20
|
/**
|
|
21
21
|
* Returns a JSON representation of the generated CSS rules taking into account box model properties, top, right, bottom, left.
|
|
22
22
|
*
|
|
23
|
-
* @param
|
|
24
|
-
* @param
|
|
25
|
-
* @param
|
|
26
|
-
* @param
|
|
23
|
+
* @param style Style object.
|
|
24
|
+
* @param options Options object with settings to adjust how the styles are generated.
|
|
25
|
+
* @param path An array of strings representing the path to the style value in the style object.
|
|
26
|
+
* @param ruleKeys An array of CSS property keys and patterns.
|
|
27
|
+
* @param individualProperties The "sides" or individual properties for which to generate rules.
|
|
27
28
|
*
|
|
28
|
-
* @return GeneratedCSSRule[]
|
|
29
|
+
* @return GeneratedCSSRule[] CSS rules.
|
|
29
30
|
*/
|
|
30
|
-
export declare function generateBoxRules(style: Style, options: StyleOptions, path: string[],
|
|
31
|
+
export declare function generateBoxRules(style: Style, options: StyleOptions, path: string[], ruleKeys: CssRulesKeys, individualProperties?: string[]): GeneratedCSSRule[];
|
|
31
32
|
/**
|
|
32
33
|
* Returns a CSS var value from incoming style value following the pattern `var:description|context|slug`.
|
|
33
34
|
*
|
|
@@ -36,4 +37,12 @@ export declare function generateBoxRules(style: Style, options: StyleOptions, pa
|
|
|
36
37
|
* @return string A CSS var value.
|
|
37
38
|
*/
|
|
38
39
|
export declare function getCSSVarFromStyleValue(styleValue: string): string;
|
|
40
|
+
/**
|
|
41
|
+
* Capitalizes the first letter in a string.
|
|
42
|
+
*
|
|
43
|
+
* @param {string} str The string whose first letter the function will capitalize.
|
|
44
|
+
*
|
|
45
|
+
* @return string A CSS var value.
|
|
46
|
+
*/
|
|
47
|
+
export declare function upperFirst([firstLetter, ...rest]: string): string;
|
|
39
48
|
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/styles/utils.ts"],"names":[],"mappings":"AAKA;;GAEG;AACH,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/styles/utils.ts"],"names":[],"mappings":"AAKA;;GAEG;AACH,OAAO,KAAK,EACX,YAAY,EACZ,gBAAgB,EAChB,KAAK,EAEL,YAAY,EACZ,MAAM,UAAU,CAAC;AAOlB;;;;;;;;;GASG;AACH,wBAAgB,YAAY,CAC3B,KAAK,EAAE,KAAK,EACZ,OAAO,EAAE,YAAY,EACrB,IAAI,EAAE,MAAM,EAAE,EACd,OAAO,EAAE,MAAM;;;;IAaf;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,gBAAgB,CAC/B,KAAK,EAAE,KAAK,EACZ,OAAO,EAAE,YAAY,EACrB,IAAI,EAAE,MAAM,EAAE,EACd,QAAQ,EAAE,YAAY,EACtB,oBAAoB,GAAE,MAAM,EAAyC,GACnE,gBAAgB,EAAE,CAqCpB;AAED;;;;;;GAMG;AACH,wBAAgB,uBAAuB,CAAE,UAAU,EAAE,MAAM,GAAI,MAAM,CAYpE;AAED;;;;;;GAMG;AACH,wBAAgB,UAAU,CAAE,CAAE,WAAW,EAAE,GAAG,IAAI,CAAE,EAAE,MAAM,UAE3D"}
|
package/build-types/types.d.ts
CHANGED
|
@@ -9,7 +9,28 @@ export declare type Box<T extends BoxVariants = undefined> = {
|
|
|
9
9
|
bottom?: CSSProperties[T extends undefined ? 'bottom' : `${T}Bottom`];
|
|
10
10
|
left?: CSSProperties[T extends undefined ? 'left' : `${T}Left`];
|
|
11
11
|
};
|
|
12
|
+
export declare type BorderIndividualProperty = 'top' | 'right' | 'bottom' | 'left';
|
|
13
|
+
export declare type BorderIndividualStyles<T extends BorderIndividualProperty> = {
|
|
14
|
+
color?: CSSProperties[`border${Capitalize<string & T>}Color`];
|
|
15
|
+
style?: CSSProperties[`border${Capitalize<string & T>}Style`];
|
|
16
|
+
width?: CSSProperties[`border${Capitalize<string & T>}Width`];
|
|
17
|
+
};
|
|
12
18
|
export interface Style {
|
|
19
|
+
border?: {
|
|
20
|
+
color?: CSSProperties['borderColor'];
|
|
21
|
+
radius?: CSSProperties['borderRadius'] | {
|
|
22
|
+
topLeft?: CSSProperties['borderTopLeftRadius'];
|
|
23
|
+
topRight?: CSSProperties['borderTopRightRadius'];
|
|
24
|
+
bottomLeft?: CSSProperties['borderBottomLeftRadius'];
|
|
25
|
+
bottomRight?: CSSProperties['borderBottomLeftRadius'];
|
|
26
|
+
};
|
|
27
|
+
style?: CSSProperties['borderStyle'];
|
|
28
|
+
width?: CSSProperties['borderWidth'];
|
|
29
|
+
top?: BorderIndividualStyles<'top'>;
|
|
30
|
+
right?: BorderIndividualStyles<'right'>;
|
|
31
|
+
bottom?: BorderIndividualStyles<'bottom'>;
|
|
32
|
+
left?: BorderIndividualStyles<'left'>;
|
|
33
|
+
};
|
|
13
34
|
spacing?: {
|
|
14
35
|
margin?: CSSProperties['margin'] | Box<'margin'>;
|
|
15
36
|
padding?: CSSProperties['padding'] | Box<'padding'>;
|
|
@@ -37,6 +58,10 @@ export interface Style {
|
|
|
37
58
|
};
|
|
38
59
|
};
|
|
39
60
|
}
|
|
61
|
+
export declare type CssRulesKeys = {
|
|
62
|
+
default: string;
|
|
63
|
+
individual: string;
|
|
64
|
+
};
|
|
40
65
|
export declare type StyleOptions = {
|
|
41
66
|
/**
|
|
42
67
|
* CSS selector for the generated style.
|
|
@@ -54,7 +79,7 @@ export declare type GeneratedCSSRule = {
|
|
|
54
79
|
};
|
|
55
80
|
export interface StyleDefinition {
|
|
56
81
|
name: string;
|
|
57
|
-
generate?: (style: Style, options: StyleOptions) => GeneratedCSSRule[];
|
|
82
|
+
generate?: (style: Style, options: StyleOptions, path?: string[], ruleKey?: string) => GeneratedCSSRule[];
|
|
58
83
|
getClassNames?: (style: Style) => string[];
|
|
59
84
|
}
|
|
60
85
|
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AAE3C,aAAK,WAAW,GAAG,QAAQ,GAAG,SAAS,GAAG,SAAS,CAAC;AACpD,oBAAY,GAAG,CAAE,CAAC,SAAS,WAAW,GAAG,SAAS,IAAK;IACtD,GAAG,CAAC,EAAE,aAAa,CAAE,CAAC,SAAS,SAAS,GAAG,KAAK,GAAG,GAAI,CAAE,KAAK,CAAE,CAAC;IACjE,KAAK,CAAC,EAAE,aAAa,CAAE,CAAC,SAAS,SAAS,GAAG,OAAO,GAAG,GAAI,CAAE,OAAO,CAAE,CAAC;IACvE,MAAM,CAAC,EAAE,aAAa,CAAE,CAAC,SAAS,SAAS,GAAG,QAAQ,GAAG,GAAI,CAAE,QAAQ,CAAE,CAAC;IAC1E,IAAI,CAAC,EAAE,aAAa,CAAE,CAAC,SAAS,SAAS,GAAG,MAAM,GAAG,GAAI,CAAE,MAAM,CAAE,CAAC;CACpE,CAAC;AAEF,MAAM,WAAW,KAAK;IACrB,OAAO,CAAC,EAAE;QACT,MAAM,CAAC,EAAE,aAAa,CAAE,QAAQ,CAAE,GAAG,GAAG,CAAE,QAAQ,CAAE,CAAC;QACrD,OAAO,CAAC,EAAE,aAAa,CAAE,SAAS,CAAE,GAAG,GAAG,CAAE,SAAS,CAAE,CAAC;KACxD,CAAC;IACF,UAAU,CAAC,EAAE;QACZ,QAAQ,CAAC,EAAE,aAAa,CAAE,UAAU,CAAE,CAAC;QACvC,UAAU,CAAC,EAAE,aAAa,CAAE,YAAY,CAAE,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ChD,QAAQ,CAAC,EAAE,aAAa,CAAE,YAAY,CAAE,CAAC;KACzC,CAAC;IACF,QAAQ,CAAC,EAAE;QACV,IAAI,CAAC,EAAE;YACN,KAAK,CAAC,EAAE;gBACP,IAAI,CAAC,EAAE,aAAa,CAAE,OAAO,CAAE,CAAC;aAChC,CAAC;SACF,CAAC;KACF,CAAC;CACF;AAED,oBAAY,YAAY,GAAG;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,UAAU,EAAE,MAAM,CAAA;CAAE,CAAC;AAEnE,oBAAY,YAAY,GAAG;IAC1B;;OAEG;IACH,QAAQ,EAAE,MAAM,CAAC;CACjB,CAAC;AAEF,oBAAY,gBAAgB,GAAG;IAC9B,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;IACd;;;OAGG;IACH,GAAG,EAAE,MAAM,CAAC;CACZ,CAAC;AAEF,MAAM,WAAW,eAAe;IAC/B,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,CAAC,EAAE,CACV,KAAK,EAAE,KAAK,EACZ,OAAO,EAAE,YAAY,EACrB,IAAI,CAAC,EAAE,MAAM,EAAE,EACf,OAAO,CAAC,EAAE,MAAM,KACZ,gBAAgB,EAAE,CAAC;IACxB,aAAa,CAAC,EAAE,CAAE,KAAK,EAAE,KAAK,KAAM,MAAM,EAAE,CAAC;CAC7C"}
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
<?php
|
|
2
|
+
/**
|
|
3
|
+
* WP_Style_Engine_CSS_Declarations
|
|
4
|
+
*
|
|
5
|
+
* Holds, sanitizes and prints CSS rules declarations
|
|
6
|
+
*
|
|
7
|
+
* @package Gutenberg
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
if ( class_exists( 'WP_Style_Engine_CSS_Declarations' ) ) {
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Holds, sanitizes, processes and prints CSS declarations for the style engine.
|
|
16
|
+
*
|
|
17
|
+
* @access private
|
|
18
|
+
*/
|
|
19
|
+
class WP_Style_Engine_CSS_Declarations {
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* An array of CSS declarations (property => value pairs).
|
|
23
|
+
*
|
|
24
|
+
* @var array
|
|
25
|
+
*/
|
|
26
|
+
protected $declarations = array();
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Constructor for this object.
|
|
30
|
+
*
|
|
31
|
+
* If a `$declarations` array is passed, it will be used to populate
|
|
32
|
+
* the initial $declarations prop of the object by calling add_declarations().
|
|
33
|
+
*
|
|
34
|
+
* @param array $declarations An array of declarations (property => value pairs).
|
|
35
|
+
*/
|
|
36
|
+
public function __construct( $declarations = array() ) {
|
|
37
|
+
if ( empty( $declarations ) ) {
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
$this->add_declarations( $declarations );
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Add a single declaration.
|
|
45
|
+
*
|
|
46
|
+
* @param string $property The CSS property.
|
|
47
|
+
* @param string $value The CSS value.
|
|
48
|
+
*
|
|
49
|
+
* @return void
|
|
50
|
+
*/
|
|
51
|
+
public function add_declaration( $property, $value ) {
|
|
52
|
+
|
|
53
|
+
// Sanitize the property.
|
|
54
|
+
$property = $this->sanitize_property( $property );
|
|
55
|
+
// Bail early if the property is empty.
|
|
56
|
+
if ( empty( $property ) ) {
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// Trim the value. If empty, bail early.
|
|
61
|
+
$value = trim( $value );
|
|
62
|
+
if ( '' === $value ) {
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// Add the declaration property/value pair.
|
|
67
|
+
$this->declarations[ $property ] = $value;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Add multiple declarations.
|
|
72
|
+
*
|
|
73
|
+
* @param array $declarations An array of declarations.
|
|
74
|
+
*
|
|
75
|
+
* @return void
|
|
76
|
+
*/
|
|
77
|
+
public function add_declarations( $declarations ) {
|
|
78
|
+
foreach ( $declarations as $property => $value ) {
|
|
79
|
+
$this->add_declaration( $property, $value );
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Get the declarations array.
|
|
85
|
+
*
|
|
86
|
+
* @return array
|
|
87
|
+
*/
|
|
88
|
+
public function get_declarations() {
|
|
89
|
+
return $this->declarations;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Filters and compiles the CSS declarations.
|
|
94
|
+
*
|
|
95
|
+
* @return string The CSS declarations.
|
|
96
|
+
*/
|
|
97
|
+
public function get_declarations_string() {
|
|
98
|
+
$declarations_array = $this->get_declarations();
|
|
99
|
+
$declarations_output = '';
|
|
100
|
+
foreach ( $declarations_array as $property => $value ) {
|
|
101
|
+
$filtered_declaration = esc_html( safecss_filter_attr( "{$property}: {$value}" ) );
|
|
102
|
+
if ( $filtered_declaration ) {
|
|
103
|
+
$declarations_output .= $filtered_declaration . '; ';
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
return rtrim( $declarations_output );
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Sanitize property names.
|
|
111
|
+
*
|
|
112
|
+
* @param string $property The CSS property.
|
|
113
|
+
*
|
|
114
|
+
* @return string The sanitized property name.
|
|
115
|
+
*/
|
|
116
|
+
protected function sanitize_property( $property ) {
|
|
117
|
+
return sanitize_key( $property );
|
|
118
|
+
}
|
|
119
|
+
}
|