single-file-core 1.5.97 → 1.5.98

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/core/helper.js CHANGED
@@ -81,6 +81,7 @@ const DEFAULT_REPLACEMENT_CHARACTERS = ["~", "+", "?", "%", "*", ":"
81
81
  const CHARACTER_CLASS_SPECIAL_CHARACTERS = ["[", "]", "^", "-", "\\"];
82
82
  const NESTING_TRACK_ID_ATTRIBUTE_NAME = "data-sf-nesting-track-id";
83
83
  const addEventListener = (type, listener, options) => globalThis.addEventListener(type, listener, options);
84
+ const removeEventListener = (type, listener, options) => globalThis.removeEventListener(type, listener, options);
84
85
  // eslint-disable-next-line no-unused-vars
85
86
  const dispatchEvent = event => { try { globalThis.dispatchEvent(event); } catch (error) { /* ignored */ } };
86
87
  const JSON = globalThis.JSON;
@@ -173,30 +174,29 @@ function onInitUserScript({ detail }) {
173
174
  // ignored
174
175
  }
175
176
  const event = new CustomEvent(eventPrefixName + "-request", { cancelable: true, detail: detailUserScript });
177
+ const responseEventName = eventPrefixName + "-response";
176
178
  let resolvePromiseResponse;
177
- const promiseResponse = new Promise(resolve => {
178
- resolvePromiseResponse = resolve;
179
- addEventListener(eventPrefixName + "-response", event => {
180
- if (event.detail) {
181
- try {
182
- const detail = typeof event.detail == "string" ? JSON.parse(event.detail) : event.detail;
183
- if (detail.options) {
184
- Object.assign(options, detail.options);
185
- }
186
- // eslint-disable-next-line no-unused-vars
187
- } catch (error) {
188
- // ignored
179
+ const promiseResponse = new Promise(resolve => (resolvePromiseResponse = resolve));
180
+ const onResponse = event => {
181
+ if (event.detail) {
182
+ try {
183
+ const detail = typeof event.detail == "string" ? JSON.parse(event.detail) : event.detail;
184
+ if (detail.options) {
185
+ Object.assign(options, detail.options);
189
186
  }
187
+ // eslint-disable-next-line no-unused-vars
188
+ } catch (error) {
189
+ // ignored
190
190
  }
191
- resolve();
192
- });
193
- });
191
+ }
192
+ resolvePromiseResponse();
193
+ };
194
+ addEventListener(responseEventName, onResponse);
194
195
  dispatchEvent(event);
195
196
  if (event.defaultPrevented) {
196
197
  await promiseResponse;
197
- } else {
198
- resolvePromiseResponse();
199
198
  }
199
+ removeEventListener(responseEventName, onResponse);
200
200
  };
201
201
  }
202
202
 
@@ -152,12 +152,15 @@ class ProcessorHelperCommon {
152
152
  const response = await batchRequest.addURL(resourceURL, { expectedType: "image" });
153
153
  const svgDoc = util.parseSVGContent(response.content);
154
154
  if (hashMatch && hashMatch[0]) {
155
- let symbolElement;
156
- try {
157
- symbolElement = svgDoc.querySelector(hashMatch[0]);
158
- // eslint-disable-next-line no-unused-vars
159
- } catch (error) {
160
- // ignored
155
+ const symbolId = hashMatch[0].substring(1);
156
+ let symbolElement = svgDoc.getElementById(symbolId);
157
+ if (!symbolElement) {
158
+ try {
159
+ symbolElement = svgDoc.getElementById(decodeURIComponent(symbolId));
160
+ // eslint-disable-next-line no-unused-vars
161
+ } catch (error) {
162
+ // ignored
163
+ }
161
164
  }
162
165
  if (symbolElement) {
163
166
  resourceElement.setAttribute(attributeName, hashMatch[0]);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "single-file-core",
3
- "version": "1.5.97",
3
+ "version": "1.5.98",
4
4
  "description": "SingleFile Core",
5
5
  "author": "Gildas Lormeau",
6
6
  "license": "AGPL-3.0-or-later",