vscode-css-languageservice 6.0.1 → 6.1.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.
Files changed (87) hide show
  1. package/CHANGELOG.md +3 -1
  2. package/SECURITY.md +41 -0
  3. package/lib/esm/beautify/beautify-css.js +11 -4
  4. package/lib/esm/cssLanguageService.d.ts +38 -37
  5. package/lib/esm/cssLanguageService.js +73 -72
  6. package/lib/esm/cssLanguageTypes.d.ts +238 -238
  7. package/lib/esm/cssLanguageTypes.js +42 -42
  8. package/lib/esm/data/webCustomData.js +22089 -21959
  9. package/lib/esm/languageFacts/builtinData.js +142 -142
  10. package/lib/esm/languageFacts/colors.js +469 -469
  11. package/lib/esm/languageFacts/dataManager.js +88 -88
  12. package/lib/esm/languageFacts/dataProvider.js +73 -73
  13. package/lib/esm/languageFacts/entry.js +137 -137
  14. package/lib/esm/languageFacts/facts.js +8 -8
  15. package/lib/esm/parser/cssErrors.js +48 -48
  16. package/lib/esm/parser/cssNodes.js +1511 -1502
  17. package/lib/esm/parser/cssParser.js +1606 -1534
  18. package/lib/esm/parser/cssScanner.js +592 -592
  19. package/lib/esm/parser/cssSymbolScope.js +311 -311
  20. package/lib/esm/parser/lessParser.js +715 -714
  21. package/lib/esm/parser/lessScanner.js +57 -57
  22. package/lib/esm/parser/scssErrors.js +18 -18
  23. package/lib/esm/parser/scssParser.js +806 -796
  24. package/lib/esm/parser/scssScanner.js +95 -95
  25. package/lib/esm/services/cssCodeActions.js +77 -77
  26. package/lib/esm/services/cssCompletion.js +1054 -1054
  27. package/lib/esm/services/cssFolding.js +190 -190
  28. package/lib/esm/services/cssFormatter.js +136 -136
  29. package/lib/esm/services/cssHover.js +148 -148
  30. package/lib/esm/services/cssNavigation.js +441 -378
  31. package/lib/esm/services/cssSelectionRange.js +47 -47
  32. package/lib/esm/services/cssValidation.js +41 -41
  33. package/lib/esm/services/lessCompletion.js +378 -378
  34. package/lib/esm/services/lint.js +518 -518
  35. package/lib/esm/services/lintRules.js +76 -76
  36. package/lib/esm/services/lintUtil.js +196 -196
  37. package/lib/esm/services/pathCompletion.js +157 -157
  38. package/lib/esm/services/scssCompletion.js +354 -354
  39. package/lib/esm/services/scssNavigation.js +82 -82
  40. package/lib/esm/services/selectorPrinting.js +492 -492
  41. package/lib/esm/utils/arrays.js +40 -40
  42. package/lib/esm/utils/objects.js +11 -11
  43. package/lib/esm/utils/resources.js +11 -11
  44. package/lib/esm/utils/strings.js +102 -102
  45. package/lib/umd/beautify/beautify-css.js +11 -4
  46. package/lib/umd/cssLanguageService.d.ts +38 -37
  47. package/lib/umd/cssLanguageService.js +104 -99
  48. package/lib/umd/cssLanguageTypes.d.ts +238 -238
  49. package/lib/umd/cssLanguageTypes.js +89 -89
  50. package/lib/umd/data/webCustomData.js +22102 -21972
  51. package/lib/umd/languageFacts/builtinData.js +154 -154
  52. package/lib/umd/languageFacts/colors.js +492 -492
  53. package/lib/umd/languageFacts/dataManager.js +101 -101
  54. package/lib/umd/languageFacts/dataProvider.js +86 -86
  55. package/lib/umd/languageFacts/entry.js +152 -152
  56. package/lib/umd/languageFacts/facts.js +33 -29
  57. package/lib/umd/parser/cssErrors.js +61 -61
  58. package/lib/umd/parser/cssNodes.js +1597 -1587
  59. package/lib/umd/parser/cssParser.js +1619 -1547
  60. package/lib/umd/parser/cssScanner.js +606 -606
  61. package/lib/umd/parser/cssSymbolScope.js +328 -328
  62. package/lib/umd/parser/lessParser.js +728 -727
  63. package/lib/umd/parser/lessScanner.js +70 -70
  64. package/lib/umd/parser/scssErrors.js +31 -31
  65. package/lib/umd/parser/scssParser.js +819 -809
  66. package/lib/umd/parser/scssScanner.js +108 -108
  67. package/lib/umd/services/cssCodeActions.js +90 -90
  68. package/lib/umd/services/cssCompletion.js +1067 -1067
  69. package/lib/umd/services/cssFolding.js +203 -203
  70. package/lib/umd/services/cssFormatter.js +150 -150
  71. package/lib/umd/services/cssHover.js +161 -161
  72. package/lib/umd/services/cssNavigation.js +454 -391
  73. package/lib/umd/services/cssSelectionRange.js +60 -60
  74. package/lib/umd/services/cssValidation.js +54 -54
  75. package/lib/umd/services/lessCompletion.js +391 -391
  76. package/lib/umd/services/lint.js +531 -531
  77. package/lib/umd/services/lintRules.js +91 -91
  78. package/lib/umd/services/lintUtil.js +210 -210
  79. package/lib/umd/services/pathCompletion.js +171 -171
  80. package/lib/umd/services/scssCompletion.js +367 -367
  81. package/lib/umd/services/scssNavigation.js +95 -95
  82. package/lib/umd/services/selectorPrinting.js +510 -510
  83. package/lib/umd/utils/arrays.js +55 -55
  84. package/lib/umd/utils/objects.js +25 -25
  85. package/lib/umd/utils/resources.js +26 -26
  86. package/lib/umd/utils/strings.js +120 -120
  87. package/package.json +13 -12
@@ -1,91 +1,91 @@
1
- (function (factory) {
2
- if (typeof module === "object" && typeof module.exports === "object") {
3
- var v = factory(require, exports);
4
- if (v !== undefined) module.exports = v;
5
- }
6
- else if (typeof define === "function" && define.amd) {
7
- define(["require", "exports", "../parser/cssNodes", "vscode-nls"], factory);
8
- }
9
- })(function (require, exports) {
10
- /*---------------------------------------------------------------------------------------------
11
- * Copyright (c) Microsoft Corporation. All rights reserved.
12
- * Licensed under the MIT License. See License.txt in the project root for license information.
13
- *--------------------------------------------------------------------------------------------*/
14
- 'use strict';
15
- Object.defineProperty(exports, "__esModule", { value: true });
16
- exports.LintConfigurationSettings = exports.Settings = exports.Rules = exports.Setting = exports.Rule = void 0;
17
- const nodes = require("../parser/cssNodes");
18
- const nls = require("vscode-nls");
19
- const localize = nls.loadMessageBundle();
20
- const Warning = nodes.Level.Warning;
21
- const Error = nodes.Level.Error;
22
- const Ignore = nodes.Level.Ignore;
23
- class Rule {
24
- constructor(id, message, defaultValue) {
25
- this.id = id;
26
- this.message = message;
27
- this.defaultValue = defaultValue;
28
- // nothing to do
29
- }
30
- }
31
- exports.Rule = Rule;
32
- class Setting {
33
- constructor(id, message, defaultValue) {
34
- this.id = id;
35
- this.message = message;
36
- this.defaultValue = defaultValue;
37
- // nothing to do
38
- }
39
- }
40
- exports.Setting = Setting;
41
- exports.Rules = {
42
- AllVendorPrefixes: new Rule('compatibleVendorPrefixes', localize('rule.vendorprefixes.all', "When using a vendor-specific prefix make sure to also include all other vendor-specific properties"), Ignore),
43
- IncludeStandardPropertyWhenUsingVendorPrefix: new Rule('vendorPrefix', localize('rule.standardvendorprefix.all', "When using a vendor-specific prefix also include the standard property"), Warning),
44
- DuplicateDeclarations: new Rule('duplicateProperties', localize('rule.duplicateDeclarations', "Do not use duplicate style definitions"), Ignore),
45
- EmptyRuleSet: new Rule('emptyRules', localize('rule.emptyRuleSets', "Do not use empty rulesets"), Warning),
46
- ImportStatemement: new Rule('importStatement', localize('rule.importDirective', "Import statements do not load in parallel"), Ignore),
47
- BewareOfBoxModelSize: new Rule('boxModel', localize('rule.bewareOfBoxModelSize', "Do not use width or height when using padding or border"), Ignore),
48
- UniversalSelector: new Rule('universalSelector', localize('rule.universalSelector', "The universal selector (*) is known to be slow"), Ignore),
49
- ZeroWithUnit: new Rule('zeroUnits', localize('rule.zeroWidthUnit', "No unit for zero needed"), Ignore),
50
- RequiredPropertiesForFontFace: new Rule('fontFaceProperties', localize('rule.fontFaceProperties', "@font-face rule must define 'src' and 'font-family' properties"), Warning),
51
- HexColorLength: new Rule('hexColorLength', localize('rule.hexColor', "Hex colors must consist of three, four, six or eight hex numbers"), Error),
52
- ArgsInColorFunction: new Rule('argumentsInColorFunction', localize('rule.colorFunction', "Invalid number of parameters"), Error),
53
- UnknownProperty: new Rule('unknownProperties', localize('rule.unknownProperty', "Unknown property."), Warning),
54
- UnknownAtRules: new Rule('unknownAtRules', localize('rule.unknownAtRules', "Unknown at-rule."), Warning),
55
- IEStarHack: new Rule('ieHack', localize('rule.ieHack', "IE hacks are only necessary when supporting IE7 and older"), Ignore),
56
- UnknownVendorSpecificProperty: new Rule('unknownVendorSpecificProperties', localize('rule.unknownVendorSpecificProperty', "Unknown vendor specific property."), Ignore),
57
- PropertyIgnoredDueToDisplay: new Rule('propertyIgnoredDueToDisplay', localize('rule.propertyIgnoredDueToDisplay', "Property is ignored due to the display."), Warning),
58
- AvoidImportant: new Rule('important', localize('rule.avoidImportant', "Avoid using !important. It is an indication that the specificity of the entire CSS has gotten out of control and needs to be refactored."), Ignore),
59
- AvoidFloat: new Rule('float', localize('rule.avoidFloat', "Avoid using 'float'. Floats lead to fragile CSS that is easy to break if one aspect of the layout changes."), Ignore),
60
- AvoidIdSelector: new Rule('idSelector', localize('rule.avoidIdSelector', "Selectors should not contain IDs because these rules are too tightly coupled with the HTML."), Ignore),
61
- };
62
- exports.Settings = {
63
- ValidProperties: new Setting('validProperties', localize('rule.validProperties', "A list of properties that are not validated against the `unknownProperties` rule."), [])
64
- };
65
- class LintConfigurationSettings {
66
- constructor(conf = {}) {
67
- this.conf = conf;
68
- }
69
- getRule(rule) {
70
- if (this.conf.hasOwnProperty(rule.id)) {
71
- const level = toLevel(this.conf[rule.id]);
72
- if (level) {
73
- return level;
74
- }
75
- }
76
- return rule.defaultValue;
77
- }
78
- getSetting(setting) {
79
- return this.conf[setting.id];
80
- }
81
- }
82
- exports.LintConfigurationSettings = LintConfigurationSettings;
83
- function toLevel(level) {
84
- switch (level) {
85
- case 'ignore': return nodes.Level.Ignore;
86
- case 'warning': return nodes.Level.Warning;
87
- case 'error': return nodes.Level.Error;
88
- }
89
- return null;
90
- }
91
- });
1
+ (function (factory) {
2
+ if (typeof module === "object" && typeof module.exports === "object") {
3
+ var v = factory(require, exports);
4
+ if (v !== undefined) module.exports = v;
5
+ }
6
+ else if (typeof define === "function" && define.amd) {
7
+ define(["require", "exports", "../parser/cssNodes", "vscode-nls"], factory);
8
+ }
9
+ })(function (require, exports) {
10
+ /*---------------------------------------------------------------------------------------------
11
+ * Copyright (c) Microsoft Corporation. All rights reserved.
12
+ * Licensed under the MIT License. See License.txt in the project root for license information.
13
+ *--------------------------------------------------------------------------------------------*/
14
+ 'use strict';
15
+ Object.defineProperty(exports, "__esModule", { value: true });
16
+ exports.LintConfigurationSettings = exports.Settings = exports.Rules = exports.Setting = exports.Rule = void 0;
17
+ const nodes = require("../parser/cssNodes");
18
+ const nls = require("vscode-nls");
19
+ const localize = nls.loadMessageBundle();
20
+ const Warning = nodes.Level.Warning;
21
+ const Error = nodes.Level.Error;
22
+ const Ignore = nodes.Level.Ignore;
23
+ class Rule {
24
+ constructor(id, message, defaultValue) {
25
+ this.id = id;
26
+ this.message = message;
27
+ this.defaultValue = defaultValue;
28
+ // nothing to do
29
+ }
30
+ }
31
+ exports.Rule = Rule;
32
+ class Setting {
33
+ constructor(id, message, defaultValue) {
34
+ this.id = id;
35
+ this.message = message;
36
+ this.defaultValue = defaultValue;
37
+ // nothing to do
38
+ }
39
+ }
40
+ exports.Setting = Setting;
41
+ exports.Rules = {
42
+ AllVendorPrefixes: new Rule('compatibleVendorPrefixes', localize('rule.vendorprefixes.all', "When using a vendor-specific prefix make sure to also include all other vendor-specific properties"), Ignore),
43
+ IncludeStandardPropertyWhenUsingVendorPrefix: new Rule('vendorPrefix', localize('rule.standardvendorprefix.all', "When using a vendor-specific prefix also include the standard property"), Warning),
44
+ DuplicateDeclarations: new Rule('duplicateProperties', localize('rule.duplicateDeclarations', "Do not use duplicate style definitions"), Ignore),
45
+ EmptyRuleSet: new Rule('emptyRules', localize('rule.emptyRuleSets', "Do not use empty rulesets"), Warning),
46
+ ImportStatemement: new Rule('importStatement', localize('rule.importDirective', "Import statements do not load in parallel"), Ignore),
47
+ BewareOfBoxModelSize: new Rule('boxModel', localize('rule.bewareOfBoxModelSize', "Do not use width or height when using padding or border"), Ignore),
48
+ UniversalSelector: new Rule('universalSelector', localize('rule.universalSelector', "The universal selector (*) is known to be slow"), Ignore),
49
+ ZeroWithUnit: new Rule('zeroUnits', localize('rule.zeroWidthUnit', "No unit for zero needed"), Ignore),
50
+ RequiredPropertiesForFontFace: new Rule('fontFaceProperties', localize('rule.fontFaceProperties', "@font-face rule must define 'src' and 'font-family' properties"), Warning),
51
+ HexColorLength: new Rule('hexColorLength', localize('rule.hexColor', "Hex colors must consist of three, four, six or eight hex numbers"), Error),
52
+ ArgsInColorFunction: new Rule('argumentsInColorFunction', localize('rule.colorFunction', "Invalid number of parameters"), Error),
53
+ UnknownProperty: new Rule('unknownProperties', localize('rule.unknownProperty', "Unknown property."), Warning),
54
+ UnknownAtRules: new Rule('unknownAtRules', localize('rule.unknownAtRules', "Unknown at-rule."), Warning),
55
+ IEStarHack: new Rule('ieHack', localize('rule.ieHack', "IE hacks are only necessary when supporting IE7 and older"), Ignore),
56
+ UnknownVendorSpecificProperty: new Rule('unknownVendorSpecificProperties', localize('rule.unknownVendorSpecificProperty', "Unknown vendor specific property."), Ignore),
57
+ PropertyIgnoredDueToDisplay: new Rule('propertyIgnoredDueToDisplay', localize('rule.propertyIgnoredDueToDisplay', "Property is ignored due to the display."), Warning),
58
+ AvoidImportant: new Rule('important', localize('rule.avoidImportant', "Avoid using !important. It is an indication that the specificity of the entire CSS has gotten out of control and needs to be refactored."), Ignore),
59
+ AvoidFloat: new Rule('float', localize('rule.avoidFloat', "Avoid using 'float'. Floats lead to fragile CSS that is easy to break if one aspect of the layout changes."), Ignore),
60
+ AvoidIdSelector: new Rule('idSelector', localize('rule.avoidIdSelector', "Selectors should not contain IDs because these rules are too tightly coupled with the HTML."), Ignore),
61
+ };
62
+ exports.Settings = {
63
+ ValidProperties: new Setting('validProperties', localize('rule.validProperties', "A list of properties that are not validated against the `unknownProperties` rule."), [])
64
+ };
65
+ class LintConfigurationSettings {
66
+ constructor(conf = {}) {
67
+ this.conf = conf;
68
+ }
69
+ getRule(rule) {
70
+ if (this.conf.hasOwnProperty(rule.id)) {
71
+ const level = toLevel(this.conf[rule.id]);
72
+ if (level) {
73
+ return level;
74
+ }
75
+ }
76
+ return rule.defaultValue;
77
+ }
78
+ getSetting(setting) {
79
+ return this.conf[setting.id];
80
+ }
81
+ }
82
+ exports.LintConfigurationSettings = LintConfigurationSettings;
83
+ function toLevel(level) {
84
+ switch (level) {
85
+ case 'ignore': return nodes.Level.Ignore;
86
+ case 'warning': return nodes.Level.Warning;
87
+ case 'error': return nodes.Level.Error;
88
+ }
89
+ return null;
90
+ }
91
+ });
@@ -1,210 +1,210 @@
1
- (function (factory) {
2
- if (typeof module === "object" && typeof module.exports === "object") {
3
- var v = factory(require, exports);
4
- if (v !== undefined) module.exports = v;
5
- }
6
- else if (typeof define === "function" && define.amd) {
7
- define(["require", "exports", "../utils/arrays"], factory);
8
- }
9
- })(function (require, exports) {
10
- /*---------------------------------------------------------------------------------------------
11
- * Copyright (c) Microsoft Corporation. All rights reserved.
12
- * Licensed under the MIT License. See License.txt in the project root for license information.
13
- *--------------------------------------------------------------------------------------------*/
14
- 'use strict';
15
- Object.defineProperty(exports, "__esModule", { value: true });
16
- exports.Element = void 0;
17
- const arrays_1 = require("../utils/arrays");
18
- class Element {
19
- constructor(decl) {
20
- this.fullPropertyName = decl.getFullPropertyName().toLowerCase();
21
- this.node = decl;
22
- }
23
- }
24
- exports.Element = Element;
25
- function setSide(model, side, value, property) {
26
- const state = model[side];
27
- state.value = value;
28
- if (value) {
29
- if (!(0, arrays_1.includes)(state.properties, property)) {
30
- state.properties.push(property);
31
- }
32
- }
33
- }
34
- function setAllSides(model, value, property) {
35
- setSide(model, 'top', value, property);
36
- setSide(model, 'right', value, property);
37
- setSide(model, 'bottom', value, property);
38
- setSide(model, 'left', value, property);
39
- }
40
- function updateModelWithValue(model, side, value, property) {
41
- if (side === 'top' || side === 'right' ||
42
- side === 'bottom' || side === 'left') {
43
- setSide(model, side, value, property);
44
- }
45
- else {
46
- setAllSides(model, value, property);
47
- }
48
- }
49
- function updateModelWithList(model, values, property) {
50
- switch (values.length) {
51
- case 1:
52
- updateModelWithValue(model, undefined, values[0], property);
53
- break;
54
- case 2:
55
- updateModelWithValue(model, 'top', values[0], property);
56
- updateModelWithValue(model, 'bottom', values[0], property);
57
- updateModelWithValue(model, 'right', values[1], property);
58
- updateModelWithValue(model, 'left', values[1], property);
59
- break;
60
- case 3:
61
- updateModelWithValue(model, 'top', values[0], property);
62
- updateModelWithValue(model, 'right', values[1], property);
63
- updateModelWithValue(model, 'left', values[1], property);
64
- updateModelWithValue(model, 'bottom', values[2], property);
65
- break;
66
- case 4:
67
- updateModelWithValue(model, 'top', values[0], property);
68
- updateModelWithValue(model, 'right', values[1], property);
69
- updateModelWithValue(model, 'bottom', values[2], property);
70
- updateModelWithValue(model, 'left', values[3], property);
71
- break;
72
- }
73
- }
74
- function matches(value, candidates) {
75
- for (let candidate of candidates) {
76
- if (value.matches(candidate)) {
77
- return true;
78
- }
79
- }
80
- return false;
81
- }
82
- /**
83
- * @param allowsKeywords whether the initial value of property is zero, so keywords `initial` and `unset` count as zero
84
- * @return `true` if this node represents a non-zero border; otherwise, `false`
85
- */
86
- function checkLineWidth(value, allowsKeywords = true) {
87
- if (allowsKeywords && matches(value, ['initial', 'unset'])) {
88
- return false;
89
- }
90
- // a <length> is a value and a unit
91
- // so use `parseFloat` to strip the unit
92
- return parseFloat(value.getText()) !== 0;
93
- }
94
- function checkLineWidthList(nodes, allowsKeywords = true) {
95
- return nodes.map(node => checkLineWidth(node, allowsKeywords));
96
- }
97
- /**
98
- * @param allowsKeywords whether keywords `initial` and `unset` count as zero
99
- * @return `true` if this node represents a non-zero border; otherwise, `false`
100
- */
101
- function checkLineStyle(valueNode, allowsKeywords = true) {
102
- if (matches(valueNode, ['none', 'hidden'])) {
103
- return false;
104
- }
105
- if (allowsKeywords && matches(valueNode, ['initial', 'unset'])) {
106
- return false;
107
- }
108
- return true;
109
- }
110
- function checkLineStyleList(nodes, allowsKeywords = true) {
111
- return nodes.map(node => checkLineStyle(node, allowsKeywords));
112
- }
113
- function checkBorderShorthand(node) {
114
- const children = node.getChildren();
115
- // the only child can be a keyword, a <line-width>, or a <line-style>
116
- // if either check returns false, the result is no border
117
- if (children.length === 1) {
118
- const value = children[0];
119
- return checkLineWidth(value) && checkLineStyle(value);
120
- }
121
- // multiple children can't contain keywords
122
- // if any child means no border, the result is no border
123
- for (const child of children) {
124
- const value = child;
125
- if (!checkLineWidth(value, /* allowsKeywords: */ false) ||
126
- !checkLineStyle(value, /* allowsKeywords: */ false)) {
127
- return false;
128
- }
129
- }
130
- return true;
131
- }
132
- function calculateBoxModel(propertyTable) {
133
- const model = {
134
- top: { value: false, properties: [] },
135
- right: { value: false, properties: [] },
136
- bottom: { value: false, properties: [] },
137
- left: { value: false, properties: [] },
138
- };
139
- for (const property of propertyTable) {
140
- const value = property.node.value;
141
- if (typeof value === 'undefined') {
142
- continue;
143
- }
144
- switch (property.fullPropertyName) {
145
- case 'box-sizing':
146
- // has `box-sizing`, bail out
147
- return {
148
- top: { value: false, properties: [] },
149
- right: { value: false, properties: [] },
150
- bottom: { value: false, properties: [] },
151
- left: { value: false, properties: [] },
152
- };
153
- case 'width':
154
- model.width = property;
155
- break;
156
- case 'height':
157
- model.height = property;
158
- break;
159
- default:
160
- const segments = property.fullPropertyName.split('-');
161
- switch (segments[0]) {
162
- case 'border':
163
- switch (segments[1]) {
164
- case undefined:
165
- case 'top':
166
- case 'right':
167
- case 'bottom':
168
- case 'left':
169
- switch (segments[2]) {
170
- case undefined:
171
- updateModelWithValue(model, segments[1], checkBorderShorthand(value), property);
172
- break;
173
- case 'width':
174
- // the initial value of `border-width` is `medium`, not zero
175
- updateModelWithValue(model, segments[1], checkLineWidth(value, false), property);
176
- break;
177
- case 'style':
178
- // the initial value of `border-style` is `none`
179
- updateModelWithValue(model, segments[1], checkLineStyle(value, true), property);
180
- break;
181
- }
182
- break;
183
- case 'width':
184
- // the initial value of `border-width` is `medium`, not zero
185
- updateModelWithList(model, checkLineWidthList(value.getChildren(), false), property);
186
- break;
187
- case 'style':
188
- // the initial value of `border-style` is `none`
189
- updateModelWithList(model, checkLineStyleList(value.getChildren(), true), property);
190
- break;
191
- }
192
- break;
193
- case 'padding':
194
- if (segments.length === 1) {
195
- // the initial value of `padding` is zero
196
- updateModelWithList(model, checkLineWidthList(value.getChildren(), true), property);
197
- }
198
- else {
199
- // the initial value of `padding` is zero
200
- updateModelWithValue(model, segments[1], checkLineWidth(value, true), property);
201
- }
202
- break;
203
- }
204
- break;
205
- }
206
- }
207
- return model;
208
- }
209
- exports.default = calculateBoxModel;
210
- });
1
+ (function (factory) {
2
+ if (typeof module === "object" && typeof module.exports === "object") {
3
+ var v = factory(require, exports);
4
+ if (v !== undefined) module.exports = v;
5
+ }
6
+ else if (typeof define === "function" && define.amd) {
7
+ define(["require", "exports", "../utils/arrays"], factory);
8
+ }
9
+ })(function (require, exports) {
10
+ /*---------------------------------------------------------------------------------------------
11
+ * Copyright (c) Microsoft Corporation. All rights reserved.
12
+ * Licensed under the MIT License. See License.txt in the project root for license information.
13
+ *--------------------------------------------------------------------------------------------*/
14
+ 'use strict';
15
+ Object.defineProperty(exports, "__esModule", { value: true });
16
+ exports.Element = void 0;
17
+ const arrays_1 = require("../utils/arrays");
18
+ class Element {
19
+ constructor(decl) {
20
+ this.fullPropertyName = decl.getFullPropertyName().toLowerCase();
21
+ this.node = decl;
22
+ }
23
+ }
24
+ exports.Element = Element;
25
+ function setSide(model, side, value, property) {
26
+ const state = model[side];
27
+ state.value = value;
28
+ if (value) {
29
+ if (!(0, arrays_1.includes)(state.properties, property)) {
30
+ state.properties.push(property);
31
+ }
32
+ }
33
+ }
34
+ function setAllSides(model, value, property) {
35
+ setSide(model, 'top', value, property);
36
+ setSide(model, 'right', value, property);
37
+ setSide(model, 'bottom', value, property);
38
+ setSide(model, 'left', value, property);
39
+ }
40
+ function updateModelWithValue(model, side, value, property) {
41
+ if (side === 'top' || side === 'right' ||
42
+ side === 'bottom' || side === 'left') {
43
+ setSide(model, side, value, property);
44
+ }
45
+ else {
46
+ setAllSides(model, value, property);
47
+ }
48
+ }
49
+ function updateModelWithList(model, values, property) {
50
+ switch (values.length) {
51
+ case 1:
52
+ updateModelWithValue(model, undefined, values[0], property);
53
+ break;
54
+ case 2:
55
+ updateModelWithValue(model, 'top', values[0], property);
56
+ updateModelWithValue(model, 'bottom', values[0], property);
57
+ updateModelWithValue(model, 'right', values[1], property);
58
+ updateModelWithValue(model, 'left', values[1], property);
59
+ break;
60
+ case 3:
61
+ updateModelWithValue(model, 'top', values[0], property);
62
+ updateModelWithValue(model, 'right', values[1], property);
63
+ updateModelWithValue(model, 'left', values[1], property);
64
+ updateModelWithValue(model, 'bottom', values[2], property);
65
+ break;
66
+ case 4:
67
+ updateModelWithValue(model, 'top', values[0], property);
68
+ updateModelWithValue(model, 'right', values[1], property);
69
+ updateModelWithValue(model, 'bottom', values[2], property);
70
+ updateModelWithValue(model, 'left', values[3], property);
71
+ break;
72
+ }
73
+ }
74
+ function matches(value, candidates) {
75
+ for (let candidate of candidates) {
76
+ if (value.matches(candidate)) {
77
+ return true;
78
+ }
79
+ }
80
+ return false;
81
+ }
82
+ /**
83
+ * @param allowsKeywords whether the initial value of property is zero, so keywords `initial` and `unset` count as zero
84
+ * @return `true` if this node represents a non-zero border; otherwise, `false`
85
+ */
86
+ function checkLineWidth(value, allowsKeywords = true) {
87
+ if (allowsKeywords && matches(value, ['initial', 'unset'])) {
88
+ return false;
89
+ }
90
+ // a <length> is a value and a unit
91
+ // so use `parseFloat` to strip the unit
92
+ return parseFloat(value.getText()) !== 0;
93
+ }
94
+ function checkLineWidthList(nodes, allowsKeywords = true) {
95
+ return nodes.map(node => checkLineWidth(node, allowsKeywords));
96
+ }
97
+ /**
98
+ * @param allowsKeywords whether keywords `initial` and `unset` count as zero
99
+ * @return `true` if this node represents a non-zero border; otherwise, `false`
100
+ */
101
+ function checkLineStyle(valueNode, allowsKeywords = true) {
102
+ if (matches(valueNode, ['none', 'hidden'])) {
103
+ return false;
104
+ }
105
+ if (allowsKeywords && matches(valueNode, ['initial', 'unset'])) {
106
+ return false;
107
+ }
108
+ return true;
109
+ }
110
+ function checkLineStyleList(nodes, allowsKeywords = true) {
111
+ return nodes.map(node => checkLineStyle(node, allowsKeywords));
112
+ }
113
+ function checkBorderShorthand(node) {
114
+ const children = node.getChildren();
115
+ // the only child can be a keyword, a <line-width>, or a <line-style>
116
+ // if either check returns false, the result is no border
117
+ if (children.length === 1) {
118
+ const value = children[0];
119
+ return checkLineWidth(value) && checkLineStyle(value);
120
+ }
121
+ // multiple children can't contain keywords
122
+ // if any child means no border, the result is no border
123
+ for (const child of children) {
124
+ const value = child;
125
+ if (!checkLineWidth(value, /* allowsKeywords: */ false) ||
126
+ !checkLineStyle(value, /* allowsKeywords: */ false)) {
127
+ return false;
128
+ }
129
+ }
130
+ return true;
131
+ }
132
+ function calculateBoxModel(propertyTable) {
133
+ const model = {
134
+ top: { value: false, properties: [] },
135
+ right: { value: false, properties: [] },
136
+ bottom: { value: false, properties: [] },
137
+ left: { value: false, properties: [] },
138
+ };
139
+ for (const property of propertyTable) {
140
+ const value = property.node.value;
141
+ if (typeof value === 'undefined') {
142
+ continue;
143
+ }
144
+ switch (property.fullPropertyName) {
145
+ case 'box-sizing':
146
+ // has `box-sizing`, bail out
147
+ return {
148
+ top: { value: false, properties: [] },
149
+ right: { value: false, properties: [] },
150
+ bottom: { value: false, properties: [] },
151
+ left: { value: false, properties: [] },
152
+ };
153
+ case 'width':
154
+ model.width = property;
155
+ break;
156
+ case 'height':
157
+ model.height = property;
158
+ break;
159
+ default:
160
+ const segments = property.fullPropertyName.split('-');
161
+ switch (segments[0]) {
162
+ case 'border':
163
+ switch (segments[1]) {
164
+ case undefined:
165
+ case 'top':
166
+ case 'right':
167
+ case 'bottom':
168
+ case 'left':
169
+ switch (segments[2]) {
170
+ case undefined:
171
+ updateModelWithValue(model, segments[1], checkBorderShorthand(value), property);
172
+ break;
173
+ case 'width':
174
+ // the initial value of `border-width` is `medium`, not zero
175
+ updateModelWithValue(model, segments[1], checkLineWidth(value, false), property);
176
+ break;
177
+ case 'style':
178
+ // the initial value of `border-style` is `none`
179
+ updateModelWithValue(model, segments[1], checkLineStyle(value, true), property);
180
+ break;
181
+ }
182
+ break;
183
+ case 'width':
184
+ // the initial value of `border-width` is `medium`, not zero
185
+ updateModelWithList(model, checkLineWidthList(value.getChildren(), false), property);
186
+ break;
187
+ case 'style':
188
+ // the initial value of `border-style` is `none`
189
+ updateModelWithList(model, checkLineStyleList(value.getChildren(), true), property);
190
+ break;
191
+ }
192
+ break;
193
+ case 'padding':
194
+ if (segments.length === 1) {
195
+ // the initial value of `padding` is zero
196
+ updateModelWithList(model, checkLineWidthList(value.getChildren(), true), property);
197
+ }
198
+ else {
199
+ // the initial value of `padding` is zero
200
+ updateModelWithValue(model, segments[1], checkLineWidth(value, true), property);
201
+ }
202
+ break;
203
+ }
204
+ break;
205
+ }
206
+ }
207
+ return model;
208
+ }
209
+ exports.default = calculateBoxModel;
210
+ });