@wandzai/utils 1.0.74-benchmark-classifications-7 → 1.0.74-gen-ai-activations-comparison-1

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wandzai/utils",
3
- "version": "1.0.74-benchmark-classifications-7",
3
+ "version": "1.0.74-gen-ai-activations-comparison-1",
4
4
  "description": "Common used utilities library",
5
5
  "main": "src/index",
6
6
  "scripts": {
package/src/bee-free.d.ts CHANGED
@@ -1 +1,2 @@
1
- export declare const extractAllTextFromEntityJson: (json: any) => string[];
1
+ import { InteractionViewModes } from '@wandzai/wandz-interfaces';
2
+ export declare const extractAllTextFromEntityJson: (json: any, device: InteractionViewModes | null) => string[];
package/src/bee-free.js CHANGED
@@ -1,24 +1,48 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.extractAllTextFromEntityJson = void 0;
4
- const extractAllTextFromEntityJson = (json) => {
4
+ const html_entities_1 = require("html-entities");
5
+ const wandz_interfaces_1 = require("@wandzai/wandz-interfaces");
6
+ const extractAllTextFromEntityJson = (json, device) => {
5
7
  const values = [];
6
- for (const row of json.page.rows) {
7
- for (const column of row.columns) {
8
- for (const module of column.modules) {
8
+ const stripHtml = (html) => (0, html_entities_1.decode)(html
9
+ .replace(/<style[^>]*>.*?<\/style>/gi, '')
10
+ .replace(/<script[^>]*>.*?<\/script>/gi, '')
11
+ .replace(/<[^>]+>/g, '')
12
+ .replace(/\s+/g, ' ')
13
+ .trim());
14
+ const isRowVisibleForDevice = (row) => {
15
+ const style = row.content?.computedStyle ?? {};
16
+ const hideDesktop = style.hideContentOnDesktop === true;
17
+ const hideMobile = style.hideContentOnMobile === true;
18
+ if (device === wandz_interfaces_1.InteractionViewModes.DESKTOP) {
19
+ return !hideDesktop;
20
+ }
21
+ if (device === wandz_interfaces_1.InteractionViewModes.MOBILE) {
22
+ return !hideMobile;
23
+ }
24
+ return !(hideDesktop && hideMobile);
25
+ };
26
+ for (const row of json.page?.rows ?? []) {
27
+ if (!isRowVisibleForDevice(row))
28
+ continue;
29
+ for (const column of row.columns ?? []) {
30
+ for (const module of column.modules ?? []) {
9
31
  const descriptor = module.descriptor;
10
- for (const key in descriptor) {
11
- const value = descriptor[key];
12
- if (value?.text) {
13
- const div = document.createElement('div');
14
- div.innerHTML = value?.text;
15
- values.push(div.textContent?.trim() || '');
16
- }
32
+ if (descriptor?.paragraph?.html) {
33
+ const text = stripHtml(descriptor.paragraph.html);
34
+ if (text)
35
+ values.push(text);
36
+ }
37
+ if (descriptor?.button?.label) {
38
+ const text = stripHtml(descriptor.button.label);
39
+ if (text)
40
+ values.push(text);
17
41
  }
18
42
  }
19
43
  }
20
44
  }
21
- return values;
45
+ return device == null ? Array.from(new Set(values)) : values;
22
46
  };
23
47
  exports.extractAllTextFromEntityJson = extractAllTextFromEntityJson;
24
48
  //# sourceMappingURL=bee-free.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"bee-free.js","sourceRoot":"","sources":["../../../../libs/utils/src/bee-free.ts"],"names":[],"mappings":";;;AAEO,MAAM,4BAA4B,GAAG,CAAC,IAAI,EAAqC,EAAE;IACtF,MAAM,MAAM,GAAa,EAAE,CAAC;IAE5B,KAAK,MAAM,GAAG,IAAI,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC;QACjC,KAAK,MAAM,MAAM,IAAI,GAAG,CAAC,OAAO,EAAE,CAAC;YACjC,KAAK,MAAM,MAAM,IAAI,MAAM,CAAC,OAAO,EAAE,CAAC;gBACpC,MAAM,UAAU,GAAG,MAAM,CAAC,UAAU,CAAC;gBAErC,KAAK,MAAM,GAAG,IAAI,UAAU,EAAE,CAAC;oBAC7B,MAAM,KAAK,GAAG,UAAU,CAAC,GAAG,CAAC,CAAC;oBAG9B,IAAI,KAAK,EAAE,IAAI,EAAE,CAAC;wBAChB,MAAM,GAAG,GAAG,QAAQ,CAAC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