@lvce-editor/renderer-process 30.9.0 → 30.10.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.
@@ -119,7 +119,8 @@ const confirm$1 = message => {
119
119
  };
120
120
 
121
121
  const state$a = {
122
- styleSheets: Object.create(null)
122
+ styleSheets: Object.create(null),
123
+ texts: Object.create(null)
123
124
  };
124
125
  const set$a = (id, sheet) => {
125
126
  state$a.styleSheets[id] = sheet;
@@ -127,18 +128,57 @@ const set$a = (id, sheet) => {
127
128
  const get$b = id => {
128
129
  return state$a.styleSheets[id];
129
130
  };
131
+ const setText$2 = (id, text) => {
132
+ state$a.texts[id] = text;
133
+ };
134
+ const getText = id => {
135
+ return state$a.texts[id];
136
+ };
137
+ const remove$4 = id => {
138
+ delete state$a.styleSheets[id];
139
+ delete state$a.texts[id];
140
+ };
130
141
 
131
142
  const addCssStyleSheet = (id, text) => {
132
143
  const existing = get$b(id);
133
144
  if (existing) {
134
145
  existing.replaceSync(text);
146
+ setText$2(id, text);
135
147
  return;
136
148
  }
137
149
  const sheet = new CSSStyleSheet({});
138
150
  set$a(id, sheet);
151
+ setText$2(id, text);
139
152
  sheet.replaceSync(text);
140
153
  document.adoptedStyleSheets.push(sheet);
141
154
  };
155
+ const patchCssStyleSheet = (id, start, deleteCount, replacement) => {
156
+ const sheet = get$b(id);
157
+ const text = getText(id);
158
+ if (!sheet || typeof text !== 'string') {
159
+ throw new Error(`stylesheet ${id} must be initialized before it can be patched`);
160
+ }
161
+ if (!Number.isSafeInteger(start) || start < 0 || start > text.length) {
162
+ throw new TypeError('start must be an integer within the stylesheet');
163
+ }
164
+ if (!Number.isSafeInteger(deleteCount) || deleteCount < 0 || start + deleteCount > text.length) {
165
+ throw new TypeError('deleteCount must be an integer within the stylesheet');
166
+ }
167
+ if (typeof replacement !== 'string') {
168
+ throw new TypeError('replacement must be a string');
169
+ }
170
+ const newText = text.slice(0, start) + replacement + text.slice(start + deleteCount);
171
+ sheet.replaceSync(newText);
172
+ setText$2(id, newText);
173
+ };
174
+ const removeCssStyleSheet = id => {
175
+ const sheet = get$b(id);
176
+ if (!sheet) {
177
+ return;
178
+ }
179
+ document.adoptedStyleSheets = document.adoptedStyleSheets.filter(candidate => candidate !== sheet);
180
+ remove$4(id);
181
+ };
142
182
  const getSelectionText = () => {
143
183
  return document.getSelection()?.toString() || '';
144
184
  };
@@ -8834,6 +8874,7 @@ const dispose$4 = id => {
8834
8874
  if (instance.state.$Viewlet?.isConnected) {
8835
8875
  instance.state.$Viewlet.remove();
8836
8876
  }
8877
+ removeCssStyleSheet(id);
8837
8878
  set$9(id, undefined);
8838
8879
  } catch {
8839
8880
  throw new Error(`Failed to dispose ${id}`);
@@ -9051,6 +9092,7 @@ const commandHandlers = {
9051
9092
  'Viewlet.focusSelector': focusSelector,
9052
9093
  'Viewlet.handleError': handleError$1,
9053
9094
  'Viewlet.move': move,
9095
+ 'Viewlet.patchCss': patchCssStyleSheet,
9054
9096
  'Viewlet.registerEventListeners': registerEventListeners,
9055
9097
  'Viewlet.removeKeyBindings': removeKeyBindings,
9056
9098
  'Viewlet.replaceChildren': replaceChildren,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/renderer-process",
3
- "version": "30.9.0",
3
+ "version": "30.10.0",
4
4
  "keywords": [
5
5
  "lvce-editor",
6
6
  "renderer-process"