@node-projects/web-component-designer 0.0.170 → 0.0.171

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 (27) hide show
  1. package/dist/elements/helper/CssUnitConverter.d.ts +2 -2
  2. package/dist/elements/helper/CssUnitConverter.js +3 -3
  3. package/dist/elements/helper/GridHelper.d.ts +2 -0
  4. package/dist/elements/helper/GridHelper.js +16 -1
  5. package/dist/elements/item/DesignItem.d.ts +1 -0
  6. package/dist/elements/item/DesignItem.js +10 -7
  7. package/dist/elements/services/propertiesService/PropertyGroupsService.d.ts +2 -2
  8. package/dist/elements/services/propertiesService/services/CssCurrentPropertiesService.d.ts +2 -2
  9. package/dist/elements/services/propertiesService/services/CssCurrentPropertiesService.js +24 -7
  10. package/dist/elements/services/propertiesService/services/CssProperties.json +541 -0
  11. package/dist/elements/services/propertiesService/services/CssPropertiesService.d.ts +4 -4
  12. package/dist/elements/services/propertiesService/services/CssPropertiesService.js +42 -167
  13. package/dist/elements/services/propertiesService/services/NativeElementsPropertiesService.js +6 -0
  14. package/dist/elements/services/stylesheetService/CssToolsStylesheetService.d.ts +17 -0
  15. package/dist/elements/services/stylesheetService/CssToolsStylesheetService.js +45 -0
  16. package/dist/elements/services/stylesheetService/CssTreeStylesheetService copy.d.ts +48 -0
  17. package/dist/elements/services/stylesheetService/CssTreeStylesheetService copy.js +185 -0
  18. package/dist/elements/services/stylesheetService/CssTreeStylesheetService.d.ts +3 -3
  19. package/dist/elements/services/stylesheetService/CssTreeStylesheetService.js +32 -17
  20. package/dist/elements/services/stylesheetService/IStylesheetService.d.ts +4 -4
  21. package/dist/elements/widgets/designerView/extensions/GridExtension.d.ts +35 -4
  22. package/dist/elements/widgets/designerView/extensions/GridExtension.js +277 -90
  23. package/dist/elements/widgets/designerView/extensions/GridExtensionProvider.js +3 -1
  24. package/dist/elements/widgets/designerView/extensions/TransformOriginExtension.js +1 -1
  25. package/dist/index.d.ts +1 -0
  26. package/dist/index.js +1 -0
  27. package/package.json +2 -1
@@ -2,181 +2,48 @@ import { BindingTarget } from '../../../item/BindingTarget.js';
2
2
  import { PropertyType } from '../PropertyType.js';
3
3
  import { CommonPropertiesService } from './CommonPropertiesService.js';
4
4
  import { RefreshMode } from '../IPropertiesService.js';
5
+ import cssProperties from './CssProperties.json' assert { type: 'json' };
5
6
  export class CssPropertiesService extends CommonPropertiesService {
6
7
  getRefreshMode(designItem) {
7
8
  return RefreshMode.none;
8
9
  }
10
+ //metrics
9
11
  layout = [
10
- {
11
- name: "display",
12
- type: "list",
13
- values: ["block", "inline", "inline-block", "flex", "inline-flex", "contents", "grid", "inline-grid", "inherit", "initial", "none"],
14
- service: this,
15
- propertyType: PropertyType.cssValue
16
- },
17
- {
18
- name: "color",
19
- type: "color",
20
- service: this,
21
- propertyType: PropertyType.cssValue
22
- }, {
23
- name: "background-color",
24
- type: "color",
25
- service: this,
26
- propertyType: PropertyType.cssValue
27
- }, {
28
- name: "box-sizing",
29
- type: "list",
30
- values: ["border-box", "content-box"],
31
- service: this,
32
- propertyType: PropertyType.cssValue
33
- }, {
34
- name: "border",
35
- type: "string",
36
- default: "0px none rbg(0,0,0)",
37
- service: this,
38
- propertyType: PropertyType.cssValue
39
- }, {
40
- name: "box-shadow",
41
- type: "string",
42
- default: "none",
43
- service: this,
44
- propertyType: PropertyType.cssValue
45
- }, {
46
- name: "opacity",
47
- type: "number",
48
- min: 0,
49
- max: 1,
50
- step: 0.1,
51
- service: this,
52
- propertyType: PropertyType.cssValue
53
- }, {
54
- name: "metrics",
55
- type: "metrics",
56
- service: this,
57
- propertyType: PropertyType.complex
58
- }, {
59
- name: "position",
60
- type: "list",
61
- values: ["static", "relative", "absolute"],
62
- service: this,
63
- propertyType: PropertyType.cssValue
64
- }, {
65
- name: "font-size",
66
- type: "css-length",
67
- service: this,
68
- propertyType: PropertyType.cssValue
69
- }, {
70
- name: "font-weight",
71
- type: "list",
72
- values: ["normal", "bold", "100", "200", "300", "400", "500", "600", "700", "800", "900", "lighter", "bolder"],
73
- service: this,
74
- propertyType: PropertyType.cssValue
75
- }
12
+ "display",
13
+ "color",
14
+ "background-color",
15
+ "box-sizing",
16
+ "border",
17
+ "box-shadow",
18
+ "opacity",
19
+ "position",
20
+ "font-size",
21
+ "font-weight",
22
+ "inset",
23
+ "margin",
24
+ "border",
25
+ "padding"
76
26
  ];
77
27
  grid = [
78
- {
79
- name: "display",
80
- type: "list",
81
- values: ["block", "inline-block", "flex", "contents", "grid", "inherit", "initial", "none"],
82
- service: this,
83
- propertyType: PropertyType.cssValue
84
- }, {
85
- name: "position",
86
- type: "list",
87
- values: ["static", "relative", "absolute"],
88
- service: this,
89
- propertyType: PropertyType.cssValue
90
- }, {
91
- name: "grid-template-columns",
92
- type: "string",
93
- service: this,
94
- propertyType: PropertyType.cssValue
95
- }, {
96
- name: "grid-template-rows",
97
- type: "string",
98
- service: this,
99
- propertyType: PropertyType.cssValue
100
- }, {
101
- name: "column-gap",
102
- type: "css-length",
103
- service: this,
104
- propertyType: PropertyType.cssValue
105
- }, {
106
- name: "row-gap",
107
- type: "css-length",
108
- service: this,
109
- propertyType: PropertyType.cssValue
110
- }, {
111
- name: "align-content",
112
- type: "img-list",
113
- values: ["center", "space-between", "space-around", "space-evenly", "stretch"],
114
- service: this,
115
- propertyType: PropertyType.cssValue
116
- }, {
117
- name: "justify-content",
118
- type: "img-list",
119
- values: ["center", "start", "end", "space-between", "space-around", "space-evenly"],
120
- service: this,
121
- propertyType: PropertyType.cssValue
122
- }, {
123
- name: "align-items",
124
- type: "img-list",
125
- values: ["center", "start", "end", "stretch", "baseline"],
126
- service: this,
127
- propertyType: PropertyType.cssValue
128
- }, {
129
- name: "justify-items",
130
- type: "img-list",
131
- values: ["center", "start", "end", "stretch"],
132
- service: this,
133
- propertyType: PropertyType.cssValue
134
- }
28
+ "display",
29
+ "position",
30
+ "grid-template-columns",
31
+ "grid-template-rows",
32
+ "column-gap",
33
+ "row-gap",
34
+ "align-content",
35
+ "justify-content",
36
+ "align-items",
37
+ "justify-items"
135
38
  ];
136
39
  flex = [
137
- {
138
- name: "display",
139
- type: "list",
140
- values: ["block", "inline-block", "flex", "contents", "grid", "inherit", "initial", "none"],
141
- service: this,
142
- propertyType: PropertyType.cssValue
143
- }, {
144
- name: "position",
145
- type: "list",
146
- values: ["static", "relative", "absolute"],
147
- service: this,
148
- propertyType: PropertyType.cssValue
149
- }, {
150
- name: "flex-direction",
151
- type: "img-list",
152
- values: ["row", "column"],
153
- service: this,
154
- propertyType: PropertyType.cssValue
155
- }, {
156
- name: "flex-wrap",
157
- type: "img-list",
158
- values: ["nowrap", "wrap"],
159
- service: this,
160
- propertyType: PropertyType.cssValue
161
- }, {
162
- name: "align-content",
163
- type: "img-list",
164
- values: ["center", "flex-start", "flex-end", "space-between", "space-around", "stretch"],
165
- service: this,
166
- propertyType: PropertyType.cssValue
167
- }, {
168
- name: "justify-content",
169
- type: "img-list",
170
- values: ["center", "flex-start", "flex-end", "space-between", "space-around", "space-evenly"],
171
- service: this,
172
- propertyType: PropertyType.cssValue
173
- }, {
174
- name: "align-items",
175
- type: "img-list",
176
- values: ["center", "flex-start", "flex-end", "stretch", "baseline"],
177
- service: this,
178
- propertyType: PropertyType.cssValue
179
- }
40
+ "display",
41
+ "position",
42
+ "flex-direction",
43
+ "flex-wrap",
44
+ "align-content",
45
+ "justify-content",
46
+ "align-items"
180
47
  ];
181
48
  constructor(name) {
182
49
  super();
@@ -189,7 +56,15 @@ export class CssPropertiesService extends CommonPropertiesService {
189
56
  return this[this.name][name];
190
57
  }
191
58
  getProperties(designItem) {
192
- return this[this.name];
59
+ const propNames = this[this.name];
60
+ const propertiesList = propNames.map(x => ({
61
+ name: x,
62
+ type: cssProperties[x]?.type ?? 'string',
63
+ values: cssProperties[x]?.values ? [...cssProperties[x]?.values, 'initial', 'inherit', 'unset'] : ['initial', 'inherit', 'unset'],
64
+ service: this,
65
+ propertyType: PropertyType.cssValue
66
+ }));
67
+ return propertiesList;
193
68
  }
194
69
  getPropertyTarget(designItem, property) {
195
70
  return BindingTarget.css;
@@ -77,6 +77,12 @@ export class NativeElementsPropertiesService extends CommonPropertiesService {
77
77
  }
78
78
  ];
79
79
  selectProperties = [
80
+ {
81
+ name: "value",
82
+ type: "string",
83
+ service: this,
84
+ propertyType: PropertyType.property
85
+ },
80
86
  {
81
87
  name: "size",
82
88
  type: "number",
@@ -0,0 +1,17 @@
1
+ import { IDesignItem } from "../../item/IDesignItem.js";
2
+ import { IStyleDeclaration, IStyleRule, IStylesheet, IStylesheetService } from "./IStylesheetService.js";
3
+ import { TypedEvent } from "@node-projects/base-custom-webcomponent";
4
+ export declare class CssToolsStylesheetService implements IStylesheetService {
5
+ private _stylesheets;
6
+ stylesheetChanged: TypedEvent<{
7
+ stylesheet: IStylesheet;
8
+ }>;
9
+ stylesheetsChanged: TypedEvent<void>;
10
+ setStylesheets(stylesheets: IStylesheet[]): Promise<void>;
11
+ getStylesheets(): IStylesheet[];
12
+ getAppliedRules(designItem: IDesignItem): IStyleRule[];
13
+ getDeclarations(designItem: IDesignItem, styleName: string): IStyleDeclaration[];
14
+ updateDeclarationWithDeclaration(declaration: IStyleDeclaration, value: string, important: boolean): boolean;
15
+ insertDeclarationIntoRule(rule: IStyleRule, declaration: IStyleDeclaration, important: boolean): boolean;
16
+ removeDeclarationFromRule(rule: IStyleRule, declaration: IStyleDeclaration): boolean;
17
+ }
@@ -0,0 +1,45 @@
1
+ import { TypedEvent } from "@node-projects/base-custom-webcomponent";
2
+ export class CssToolsStylesheetService {
3
+ _stylesheets = new Map();
4
+ stylesheetChanged = new TypedEvent();
5
+ stylesheetsChanged = new TypedEvent();
6
+ async setStylesheets(stylesheets) {
7
+ if (stylesheets != null) {
8
+ let tools = await import('@adobe/css-tools');
9
+ this._stylesheets = new Map();
10
+ for (let stylesheet of stylesheets) {
11
+ this._stylesheets.set(stylesheet.name, {
12
+ stylesheet: stylesheet,
13
+ ast: tools.parse(stylesheet.stylesheet)
14
+ });
15
+ }
16
+ this.stylesheetsChanged.emit();
17
+ }
18
+ else {
19
+ this._stylesheets = null;
20
+ }
21
+ }
22
+ getStylesheets() {
23
+ let stylesheets = [];
24
+ for (let item of this._stylesheets) {
25
+ stylesheets.push(item[1].stylesheet);
26
+ }
27
+ ;
28
+ return stylesheets;
29
+ }
30
+ getAppliedRules(designItem) {
31
+ return null;
32
+ }
33
+ getDeclarations(designItem, styleName) {
34
+ return null;
35
+ }
36
+ updateDeclarationWithDeclaration(declaration, value, important) {
37
+ return true;
38
+ }
39
+ insertDeclarationIntoRule(rule, declaration, important) {
40
+ return true;
41
+ }
42
+ removeDeclarationFromRule(rule, declaration) {
43
+ return true;
44
+ }
45
+ }
@@ -0,0 +1,48 @@
1
+ import { IDesignItem } from "../../item/IDesignItem.js";
2
+ import { IProperty } from "../propertiesService/IProperty.js";
3
+ import { IStyleDeclaration, IStyleRule, IStylesheet, IStylesheetService } from "./IStylesheetService.js";
4
+ import type * as csstree from 'css-tree';
5
+ import { TypedEvent } from "@node-projects/base-custom-webcomponent";
6
+ declare global {
7
+ interface Window {
8
+ csstree: {
9
+ fromPlainObject(node: csstree.CssNodePlain): csstree.CssNode;
10
+ toPlainObject(node: csstree.CssNode): csstree.CssNodePlain;
11
+ parse(text: string, options?: csstree.ParseOptions): csstree.CssNode;
12
+ generate(ast: csstree.CssNode, options?: csstree.GenerateOptions): string;
13
+ };
14
+ }
15
+ }
16
+ interface IRuleWithAST extends IStyleRule {
17
+ ast: csstree.RulePlain;
18
+ declarations: IDeclarationWithAST[];
19
+ }
20
+ interface IDeclarationWithAST extends IStyleDeclaration {
21
+ ast: csstree.DeclarationPlain;
22
+ parent: IStyleRule;
23
+ }
24
+ export declare class CssTreeStylesheetService implements IStylesheetService {
25
+ private _stylesheets;
26
+ stylesheetChanged: TypedEvent<{
27
+ stylesheet: IStylesheet;
28
+ }>;
29
+ stylesheetsChanged: TypedEvent<void>;
30
+ constructor();
31
+ setStylesheets(stylesheets: IStylesheet[]): void;
32
+ getStylesheets(): IStylesheet[];
33
+ private getAppliedRulesInternal;
34
+ getAppliedRules(designItem: IDesignItem): IRuleWithAST[];
35
+ private getDeclarationInternal;
36
+ getDeclarations(designItem: IDesignItem, prop: IProperty): IDeclarationWithAST[];
37
+ updateDeclarationWithProperty(designItem: IDesignItem, property: IProperty, value: string, important: boolean): boolean;
38
+ updateDeclarationWithDeclaration(declaration: IDeclarationWithAST, value: string, important: boolean): boolean;
39
+ private rulesFromAST;
40
+ private astHasChildren;
41
+ private buildSelectorString;
42
+ private getSpecificity;
43
+ private findDeclarationInRule;
44
+ private elementMatchesASelector;
45
+ private buildAtRuleString;
46
+ private sortDeclarations;
47
+ }
48
+ export {};
@@ -0,0 +1,185 @@
1
+ import { TypedEvent } from "@node-projects/base-custom-webcomponent";
2
+ import { calculate as calculateSpecifity } from "./SpecificityCalculator.js";
3
+ export class CssTreeStylesheetService {
4
+ _stylesheets = new Map();
5
+ stylesheetChanged = new TypedEvent();
6
+ stylesheetsChanged = new TypedEvent();
7
+ constructor() { }
8
+ setStylesheets(stylesheets) {
9
+ if (stylesheets != null) {
10
+ this._stylesheets = new Map();
11
+ for (let stylesheet of stylesheets) {
12
+ this._stylesheets.set(stylesheet.name, {
13
+ stylesheet: stylesheet,
14
+ ast: window.csstree.toPlainObject((window.csstree.parse(stylesheet.stylesheet, { positions: true, parseValue: false })))
15
+ });
16
+ }
17
+ this.stylesheetsChanged.emit();
18
+ }
19
+ else {
20
+ this._stylesheets = null;
21
+ }
22
+ }
23
+ getStylesheets() {
24
+ let stylesheets = [];
25
+ for (let item of this._stylesheets) {
26
+ stylesheets.push(item[1].stylesheet);
27
+ }
28
+ ;
29
+ return stylesheets;
30
+ }
31
+ /* Section covers the retrieval of rules and declarations */
32
+ getAppliedRulesInternal(designItem) {
33
+ let styles = [];
34
+ for (let item of this._stylesheets) {
35
+ if (!item[1].ast || !this.astHasChildren(item[1].ast))
36
+ break;
37
+ styles = styles.concat(Array.from(this.rulesFromAST(item[1].ast, item[1].stylesheet.stylesheet, item[0], designItem)));
38
+ }
39
+ ;
40
+ return styles;
41
+ }
42
+ getAppliedRules(designItem) {
43
+ let rules = this.getAppliedRulesInternal(designItem);
44
+ if (!rules || rules.length == 0)
45
+ return [];
46
+ let retCollection = [];
47
+ for (let rule of rules) {
48
+ retCollection.push({
49
+ ...rule,
50
+ declarations: rule.ast.block.children.map((declaration) => {
51
+ return {
52
+ name: declaration.property,
53
+ value: declaration.value.value,
54
+ important: declaration.important == true,
55
+ specificity: rule.specificity,
56
+ parent: rule,
57
+ ast: declaration,
58
+ };
59
+ })
60
+ });
61
+ }
62
+ return retCollection;
63
+ }
64
+ getDeclarationInternal(designItem, prop) {
65
+ let rules = this.getAppliedRulesInternal(designItem);
66
+ if (!rules)
67
+ return null;
68
+ let declarations = [];
69
+ for (let rule of rules) {
70
+ let declaration = this.findDeclarationInRule(rule.ast, prop);
71
+ if (!declaration)
72
+ continue;
73
+ declarations.push({
74
+ ast: declaration,
75
+ parent: rule,
76
+ name: prop.name,
77
+ value: declaration.value.value,
78
+ important: declaration.important == true,
79
+ });
80
+ }
81
+ ;
82
+ return declarations;
83
+ }
84
+ getDeclarations(designItem, prop) {
85
+ let declarations = this.getDeclarationInternal(designItem, prop);
86
+ if (!declarations)
87
+ return null;
88
+ return this.sortDeclarations(declarations);
89
+ }
90
+ /* Section covers the update of rules and declarations */
91
+ updateDeclarationWithProperty(designItem, property, value, important) {
92
+ let sortedDecl = this.sortDeclarations(this.getDeclarationInternal(designItem, property));
93
+ if (!sortedDecl) {
94
+ // no declaration of property yet
95
+ return false;
96
+ }
97
+ return false;
98
+ }
99
+ updateDeclarationWithDeclaration(declaration, value, important) {
100
+ declaration.ast.value = window.csstree.toPlainObject(window.csstree.parse(declaration.name + ": " + value, { context: 'declaration', parseValue: false })).value;
101
+ this._stylesheets.get(declaration.parent.stylesheetName).stylesheet.stylesheet = window.csstree.generate(window.csstree.fromPlainObject(this._stylesheets.get(declaration.parent.stylesheetName).ast));
102
+ this.stylesheetChanged.emit({ stylesheet: this._stylesheets.get(declaration.parent.stylesheetName).stylesheet });
103
+ return true;
104
+ }
105
+ /* Section covers the internal traversal creation of rules and declarations */
106
+ *rulesFromAST(ast, stylesheet, source, designItem, previousCheck = '') {
107
+ let parent = ast["children"] != null ? ast : ast.block;
108
+ for (const child of parent.children) {
109
+ if (child.type == "Atrule") {
110
+ const currentCheck = this.buildAtRuleString(child, stylesheet);
111
+ if (currentCheck.type === "@media" && !window.matchMedia(currentCheck.sel))
112
+ continue;
113
+ if (currentCheck.type === "@supports" && !CSS.supports(currentCheck.sel))
114
+ continue;
115
+ let ruleCollection = this.rulesFromAST(child, stylesheet, source, designItem, previousCheck + currentCheck.type + " " + currentCheck.sel + "\n");
116
+ if (ruleCollection) {
117
+ for (const r of ruleCollection) {
118
+ if (!this.elementMatchesASelector(designItem, this.buildSelectorString(r.ast.prelude)))
119
+ continue;
120
+ yield r;
121
+ }
122
+ }
123
+ }
124
+ if (child.type == "Rule") {
125
+ let selectors = this.buildSelectorString(child.prelude);
126
+ if (!this.elementMatchesASelector(designItem, selectors))
127
+ continue;
128
+ yield ({
129
+ ast: child,
130
+ selector: previousCheck + this.buildSelectorString(child.prelude).join(", "),
131
+ specificity: this.getSpecificity(child.prelude),
132
+ stylesheetName: source,
133
+ declarations: null,
134
+ });
135
+ }
136
+ }
137
+ ;
138
+ }
139
+ /* Utility functions for building selectors, specificity and so on */
140
+ astHasChildren(ast) {
141
+ return ast != null && ast["children"] != null && ast["children"].length > 0;
142
+ }
143
+ buildSelectorString(selectorsAST) {
144
+ let selectors = [];
145
+ for (let selector of selectorsAST.children) {
146
+ let sel = "";
147
+ for (let fraction of selector.children) {
148
+ sel += fraction.name;
149
+ }
150
+ selectors.push(sel);
151
+ }
152
+ ;
153
+ return selectors;
154
+ }
155
+ getSpecificity(selector) {
156
+ const specificities = calculateSpecifity(selector);
157
+ let sum = 0;
158
+ specificities.forEach(specificity => sum += specificity.a * 10000 + specificity.b * 100 + specificity.c);
159
+ return sum;
160
+ }
161
+ findDeclarationInRule(rule, property) {
162
+ return rule.block.children.find(declaration => declaration.property == property.name);
163
+ }
164
+ elementMatchesASelector(designItem, selectors) {
165
+ for (const selector of selectors)
166
+ if (designItem.element.matches(selector))
167
+ return true;
168
+ return false;
169
+ }
170
+ buildAtRuleString(ast, stylesheet) {
171
+ return {
172
+ sel: stylesheet.slice(ast.prelude.loc.start.offset, ast.prelude.loc.end.offset),
173
+ type: "@" + ast.name
174
+ };
175
+ }
176
+ sortDeclarations(declarations) {
177
+ if (declarations == null || declarations.length == 0)
178
+ return null;
179
+ return declarations.sort((dec1, dec2) => {
180
+ if (dec1.parent.specificity > dec2.parent.specificity)
181
+ return -1;
182
+ return 1;
183
+ });
184
+ }
185
+ }
@@ -1,5 +1,4 @@
1
1
  import { IDesignItem } from "../../item/IDesignItem.js";
2
- import { IProperty } from "../propertiesService/IProperty.js";
3
2
  import { IStyleDeclaration, IStyleRule, IStylesheet, IStylesheetService } from "./IStylesheetService.js";
4
3
  import type * as csstree from 'css-tree';
5
4
  import { TypedEvent } from "@node-projects/base-custom-webcomponent";
@@ -33,9 +32,10 @@ export declare class CssTreeStylesheetService implements IStylesheetService {
33
32
  private getAppliedRulesInternal;
34
33
  getAppliedRules(designItem: IDesignItem): IRuleWithAST[];
35
34
  private getDeclarationInternal;
36
- getDeclarations(designItem: IDesignItem, prop: IProperty): IDeclarationWithAST[];
37
- updateDeclarationWithProperty(designItem: IDesignItem, property: IProperty, value: string, important: boolean): boolean;
35
+ getDeclarations(designItem: IDesignItem, stlyeName: string): IDeclarationWithAST[];
38
36
  updateDeclarationWithDeclaration(declaration: IDeclarationWithAST, value: string, important: boolean): boolean;
37
+ insertDeclarationIntoRule(rule: IRuleWithAST, declaration: IStyleDeclaration, important: boolean): boolean;
38
+ removeDeclarationFromRule(rule: IRuleWithAST, declaration: IDeclarationWithAST): boolean;
39
39
  private rulesFromAST;
40
40
  private astHasChildren;
41
41
  private buildSelectorString;
@@ -33,7 +33,7 @@ export class CssTreeStylesheetService {
33
33
  let styles = [];
34
34
  for (let item of this._stylesheets) {
35
35
  if (!item[1].ast || !this.astHasChildren(item[1].ast))
36
- break;
36
+ continue;
37
37
  styles = styles.concat(Array.from(this.rulesFromAST(item[1].ast, item[1].stylesheet.stylesheet, item[0], designItem)));
38
38
  }
39
39
  ;
@@ -61,19 +61,19 @@ export class CssTreeStylesheetService {
61
61
  }
62
62
  return retCollection;
63
63
  }
64
- getDeclarationInternal(designItem, prop) {
64
+ getDeclarationInternal(designItem, styleName) {
65
65
  let rules = this.getAppliedRulesInternal(designItem);
66
66
  if (!rules)
67
67
  return null;
68
68
  let declarations = [];
69
69
  for (let rule of rules) {
70
- let declaration = this.findDeclarationInRule(rule.ast, prop);
70
+ let declaration = this.findDeclarationInRule(rule.ast, styleName);
71
71
  if (!declaration)
72
72
  continue;
73
73
  declarations.push({
74
74
  ast: declaration,
75
75
  parent: rule,
76
- name: prop.name,
76
+ name: styleName,
77
77
  value: declaration.value.value,
78
78
  important: declaration.important == true,
79
79
  });
@@ -81,27 +81,37 @@ export class CssTreeStylesheetService {
81
81
  ;
82
82
  return declarations;
83
83
  }
84
- getDeclarations(designItem, prop) {
85
- let declarations = this.getDeclarationInternal(designItem, prop);
84
+ getDeclarations(designItem, stlyeName) {
85
+ let declarations = this.getDeclarationInternal(designItem, stlyeName);
86
86
  if (!declarations)
87
87
  return null;
88
88
  return this.sortDeclarations(declarations);
89
89
  }
90
90
  /* Section covers the update of rules and declarations */
91
- updateDeclarationWithProperty(designItem, property, value, important) {
92
- let sortedDecl = this.sortDeclarations(this.getDeclarationInternal(designItem, property));
93
- if (!sortedDecl) {
94
- // no declaration of property yet
95
- return false;
96
- }
97
- return false;
98
- }
99
91
  updateDeclarationWithDeclaration(declaration, value, important) {
100
92
  declaration.ast.value = window.csstree.toPlainObject(window.csstree.parse(declaration.name + ": " + value, { context: 'declaration', parseValue: false })).value;
101
93
  this._stylesheets.get(declaration.parent.stylesheetName).stylesheet.stylesheet = window.csstree.generate(window.csstree.fromPlainObject(this._stylesheets.get(declaration.parent.stylesheetName).ast));
94
+ this._stylesheets.get(declaration.parent.stylesheetName).ast = window.csstree.toPlainObject(window.csstree.fromPlainObject(this._stylesheets.get(declaration.parent.stylesheetName).ast));
102
95
  this.stylesheetChanged.emit({ stylesheet: this._stylesheets.get(declaration.parent.stylesheetName).stylesheet });
103
96
  return true;
104
97
  }
98
+ insertDeclarationIntoRule(rule, declaration, important) {
99
+ rule.ast.block.children.push(window.csstree.toPlainObject(window.csstree.parse(declaration.name + ": " + declaration.value + (declaration.important ? "!important" : ""), { context: 'declaration', parseValue: false })));
100
+ this._stylesheets.get(rule.stylesheetName).stylesheet.stylesheet = window.csstree.generate(window.csstree.fromPlainObject(this._stylesheets.get(rule.stylesheetName).ast));
101
+ this._stylesheets.get(rule.stylesheetName).ast = window.csstree.toPlainObject(window.csstree.fromPlainObject(this._stylesheets.get(rule.stylesheetName).ast));
102
+ this.stylesheetChanged.emit({ stylesheet: this._stylesheets.get(rule.stylesheetName).stylesheet });
103
+ return true;
104
+ }
105
+ removeDeclarationFromRule(rule, declaration) {
106
+ let index = rule.ast.block.children.indexOf(declaration.ast);
107
+ if (index == -1)
108
+ return false;
109
+ rule.ast.block.children.splice(index, 1);
110
+ this._stylesheets.get(rule.stylesheetName).stylesheet.stylesheet = window.csstree.generate(window.csstree.fromPlainObject(this._stylesheets.get(rule.stylesheetName).ast));
111
+ this._stylesheets.get(rule.stylesheetName).ast = window.csstree.toPlainObject(window.csstree.fromPlainObject(this._stylesheets.get(rule.stylesheetName).ast));
112
+ this.stylesheetChanged.emit({ stylesheet: this._stylesheets.get(rule.stylesheetName).stylesheet });
113
+ return true;
114
+ }
105
115
  /* Section covers the internal traversal creation of rules and declarations */
106
116
  *rulesFromAST(ast, stylesheet, source, designItem, previousCheck = '') {
107
117
  let parent = ast["children"] != null ? ast : ast.block;
@@ -145,7 +155,12 @@ export class CssTreeStylesheetService {
145
155
  for (let selector of selectorsAST.children) {
146
156
  let sel = "";
147
157
  for (let fraction of selector.children) {
148
- sel += fraction.name;
158
+ if (fraction.type == "IdSelector")
159
+ sel += "#" + fraction.name;
160
+ else if (fraction.type == "ClassSelector")
161
+ sel += "." + fraction.name;
162
+ else
163
+ sel += fraction.name;
149
164
  }
150
165
  selectors.push(sel);
151
166
  }
@@ -158,8 +173,8 @@ export class CssTreeStylesheetService {
158
173
  specificities.forEach(specificity => sum += specificity.a * 10000 + specificity.b * 100 + specificity.c);
159
174
  return sum;
160
175
  }
161
- findDeclarationInRule(rule, property) {
162
- return rule.block.children.find(declaration => declaration.property == property.name);
176
+ findDeclarationInRule(rule, styleName) {
177
+ return rule.block.children.find(declaration => declaration.property == styleName);
163
178
  }
164
179
  elementMatchesASelector(designItem, selectors) {
165
180
  for (const selector of selectors)