web-signature 0.2.3 → 0.2.4

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/dist/Signature.js CHANGED
@@ -220,7 +220,15 @@ export default class Signature {
220
220
  }
221
221
  }
222
222
  for (const node of marks) {
223
- node.replaceWith(document.createTextNode(String(template.values[Number((node.nodeValue ?? "").match(/si-mark-(\d+)/m)[1])])));
223
+ const value = template.values[Number((node.nodeValue ?? "").match(/si-mark-(\d+)/m)[1])];
224
+ if (typeof value === "object" && value.type === "unsafeHTML") {
225
+ let obj = document.createElement("div");
226
+ obj.innerHTML = value.value;
227
+ node.replaceWith(obj.firstChild);
228
+ }
229
+ else {
230
+ node.replaceWith(document.createTextNode(String(value)));
231
+ }
224
232
  }
225
233
  })();
226
234
  // Processing si-mark attributes
@@ -232,7 +240,8 @@ export default class Signature {
232
240
  if (/<!--si-mark-\d+-->/gm.test(attr.value)) {
233
241
  const match = attr.value.match(/si-mark-(\d+)/m);
234
242
  if (match) {
235
- node.setAttribute(attr.name, String(template.values[Number(match[1])]));
243
+ const value = template.values[Number(match[1])];
244
+ node.setAttribute(attr.name, String(value));
236
245
  }
237
246
  }
238
247
  }
package/dist/d/html.d.ts CHANGED
@@ -2,3 +2,7 @@ export default function html(strings: TemplateStringsArray, ...values: any[]): {
2
2
  strings: TemplateStringsArray;
3
3
  values: any[];
4
4
  };
5
+ export declare function unsafeHTML(value: any): {
6
+ type: "unsafeHTML";
7
+ value: any;
8
+ };
package/dist/d/index.d.ts CHANGED
@@ -4,4 +4,4 @@ export { default as Signature } from './Signature.js';
4
4
  export { default as Component } from './Component.js';
5
5
  export { default as Prop } from './Prop.js';
6
6
  export { default as Library } from './Library.js';
7
- export { default as html } from './html.js';
7
+ export { default as html, unsafeHTML } from './html.js';
package/dist/html.js CHANGED
@@ -1,3 +1,6 @@
1
1
  export default function html(strings, ...values) {
2
2
  return { strings, values };
3
3
  }
4
+ export function unsafeHTML(value) {
5
+ return { type: "unsafeHTML", value: value };
6
+ }
package/dist/index.js CHANGED
@@ -6,4 +6,4 @@ export { default as Signature } from './Signature.js';
6
6
  export { default as Component } from './Component.js';
7
7
  export { default as Prop } from './Prop.js';
8
8
  export { default as Library } from './Library.js';
9
- export { default as html } from './html.js';
9
+ export { default as html, unsafeHTML } from './html.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "web-signature",
3
- "version": "0.2.3",
3
+ "version": "0.2.4",
4
4
  "description": "Primitive and fast framework for rendering web interfaces",
5
5
  "license": "ISC",
6
6
  "author": "PinBib",
package/src/Signature.ts CHANGED
@@ -279,17 +279,20 @@ export default class Signature {
279
279
  }
280
280
 
281
281
  for (const node of marks) {
282
- node.replaceWith(
283
- document.createTextNode(
284
- String(
285
- template.values[Number(
286
- (
287
- (node.nodeValue ?? "").match(/si-mark-(\d+)/m) as string[]
288
- )[1]
289
- )]
290
- )
291
- )
292
- );
282
+ const value = template.values[Number(
283
+ (
284
+ (node.nodeValue ?? "").match(/si-mark-(\d+)/m) as string[]
285
+ )[1]
286
+ )];
287
+
288
+ if (typeof value === "object" && value.type === "unsafeHTML") {
289
+ let obj = document.createElement("div");
290
+ obj.innerHTML = value.value;
291
+
292
+ node.replaceWith(obj.firstChild as ChildNode);
293
+ } else {
294
+ node.replaceWith(document.createTextNode(String(value)));
295
+ }
293
296
  }
294
297
  })();
295
298
 
@@ -305,7 +308,9 @@ export default class Signature {
305
308
  const match: RegExpMatchArray = attr.value.match(/si-mark-(\d+)/m) as RegExpMatchArray;
306
309
 
307
310
  if (match) {
308
- node.setAttribute(attr.name, String(template.values[Number(match[1])]))
311
+ const value = template.values[Number(match[1])];
312
+
313
+ node.setAttribute(attr.name, String(value));
309
314
  }
310
315
  }
311
316
  }
package/src/html.ts CHANGED
@@ -3,4 +3,8 @@ export default function html(strings: TemplateStringsArray, ...values: any[]): {
3
3
  values: any[]
4
4
  } {
5
5
  return {strings, values};
6
+ }
7
+
8
+ export function unsafeHTML(value: any): { type: "unsafeHTML", value: any } {
9
+ return {type: "unsafeHTML", value: value};
6
10
  }
package/src/index.ts CHANGED
@@ -8,4 +8,4 @@ export {default as Signature} from './Signature.js';
8
8
  export {default as Component} from './Component.js';
9
9
  export {default as Prop} from './Prop.js';
10
10
  export {default as Library} from './Library.js';
11
- export {default as html} from './html.js';
11
+ export {default as html, unsafeHTML} from './html.js';