@highlight-run/rrweb 2.0.1 → 2.0.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.
Files changed (117) hide show
  1. package/dist/plugins/console-record.js +408 -609
  2. package/dist/plugins/console-record.min.js +12 -15
  3. package/dist/plugins/console-record.min.js.map +1 -1
  4. package/dist/plugins/console-replay.js +142 -271
  5. package/dist/plugins/console-replay.min.js +4 -15
  6. package/dist/plugins/console-replay.min.js.map +1 -1
  7. package/dist/plugins/sequential-id-record.js +23 -26
  8. package/dist/plugins/sequential-id-record.min.js +1 -1
  9. package/dist/plugins/sequential-id-record.min.js.map +1 -1
  10. package/dist/plugins/sequential-id-replay.js +26 -30
  11. package/dist/plugins/sequential-id-replay.min.js +1 -1
  12. package/dist/plugins/sequential-id-replay.min.js.map +1 -1
  13. package/dist/record/rrweb-record-pack.js +63 -146
  14. package/dist/record/rrweb-record-pack.min.js +3 -15
  15. package/dist/record/rrweb-record-pack.min.js.map +1 -1
  16. package/dist/record/rrweb-record.js +3002 -3118
  17. package/dist/record/rrweb-record.min.js +4 -15
  18. package/dist/record/rrweb-record.min.js.map +1 -1
  19. package/dist/replay/rrweb-replay-unpack.js +4354 -4054
  20. package/dist/replay/rrweb-replay-unpack.min.js +5 -17
  21. package/dist/replay/rrweb-replay-unpack.min.js.map +1 -1
  22. package/dist/replay/rrweb-replay.js +4286 -3984
  23. package/dist/replay/rrweb-replay.min.js +5 -17
  24. package/dist/replay/rrweb-replay.min.js.map +1 -1
  25. package/dist/rrweb-all.js +7634 -7453
  26. package/dist/rrweb-all.min.js +16 -17
  27. package/dist/rrweb-all.min.js.map +1 -1
  28. package/dist/rrweb.js +7339 -7075
  29. package/dist/rrweb.min.js +6 -17
  30. package/dist/rrweb.min.js.map +1 -1
  31. package/es/rrweb/_virtual/_rollup-plugin-web-worker-loader__helper__auto__createBase64WorkerFactory.js +12 -0
  32. package/es/rrweb/_virtual/_rollup-plugin-web-worker-loader__helper__auto__isNodeJS.js +7 -0
  33. package/es/rrweb/_virtual/_rollup-plugin-web-worker-loader__helper__browser__createBase64WorkerFactory.js +31 -0
  34. package/es/rrweb/_virtual/_rollup-plugin-web-worker-loader__helper__node__WorkerClass.js +11 -0
  35. package/es/rrweb/_virtual/_rollup-plugin-web-worker-loader__helper__node__createBase64WorkerFactory.js +18 -0
  36. package/es/rrweb/_virtual/image-bitmap-data-url-worker.js +6 -0
  37. package/es/rrweb/ext/mitt/dist/mitt.es.js +1 -1
  38. package/es/rrweb/ext/tslib/tslib.es6.js +38 -0
  39. package/es/rrweb/packages/rrdom/es/virtual-dom.js +1099 -0
  40. package/es/rrweb/packages/rrweb/src/index.js +6 -4
  41. package/es/rrweb/packages/rrweb/src/packer/base.js +1 -1
  42. package/es/rrweb/packages/rrweb/src/packer/pack.js +4 -5
  43. package/es/rrweb/packages/rrweb/src/packer/unpack.js +24 -24
  44. package/es/rrweb/packages/rrweb/src/plugins/console/record/error-stack-parser.js +175 -176
  45. package/es/rrweb/packages/rrweb/src/plugins/console/record/index.js +109 -128
  46. package/es/rrweb/packages/rrweb/src/plugins/console/record/stringify.js +125 -138
  47. package/es/rrweb/packages/rrweb/src/plugins/console/replay/index.js +88 -105
  48. package/es/rrweb/packages/rrweb/src/plugins/sequential-id/record/index.js +19 -20
  49. package/es/rrweb/packages/rrweb/src/plugins/sequential-id/replay/index.js +25 -25
  50. package/es/rrweb/packages/rrweb/src/record/iframe-manager.js +29 -30
  51. package/es/rrweb/packages/rrweb/src/record/index.js +348 -373
  52. package/es/rrweb/packages/rrweb/src/record/mutation.js +487 -528
  53. package/es/rrweb/packages/rrweb/src/record/observer.js +584 -659
  54. package/es/rrweb/packages/rrweb/src/record/observers/canvas/2d.js +44 -73
  55. package/es/rrweb/packages/rrweb/src/record/observers/canvas/canvas-manager.js +166 -87
  56. package/es/rrweb/packages/rrweb/src/record/observers/canvas/canvas.js +21 -26
  57. package/es/rrweb/packages/rrweb/src/record/observers/canvas/serialize-args.js +119 -112
  58. package/es/rrweb/packages/rrweb/src/record/observers/canvas/webgl.js +53 -72
  59. package/es/rrweb/packages/rrweb/src/record/shadow-dom-manager.js +38 -40
  60. package/es/rrweb/packages/rrweb/src/record/stylesheet-manager.js +31 -0
  61. package/es/rrweb/packages/rrweb/src/replay/canvas/2d.js +27 -23
  62. package/es/rrweb/packages/rrweb/src/replay/canvas/deserialize-args.js +67 -0
  63. package/es/rrweb/packages/rrweb/src/replay/canvas/index.js +37 -29
  64. package/es/rrweb/packages/rrweb/src/replay/canvas/webgl.js +58 -120
  65. package/es/rrweb/packages/rrweb/src/replay/index.js +1545 -1854
  66. package/es/rrweb/packages/rrweb/src/replay/machine.js +275 -315
  67. package/es/rrweb/packages/rrweb/src/replay/smoothscroll.js +216 -218
  68. package/es/rrweb/packages/rrweb/src/replay/styles/inject-style.js +7 -7
  69. package/es/rrweb/packages/rrweb/src/replay/timer.js +87 -91
  70. package/es/rrweb/packages/rrweb/src/types.js +72 -72
  71. package/es/rrweb/packages/rrweb/src/utils.js +312 -506
  72. package/es/rrweb/packages/rrweb-snapshot/es/rrweb-snapshot.js +195 -71
  73. package/lib/plugins/console-record.js +469 -627
  74. package/lib/plugins/console-replay.js +198 -268
  75. package/lib/plugins/sequential-id-record.js +19 -20
  76. package/lib/plugins/sequential-id-replay.js +25 -25
  77. package/lib/record/rrweb-record-pack.js +184 -139
  78. package/lib/record/rrweb-record.js +2473 -2425
  79. package/lib/replay/rrweb-replay-unpack.js +3797 -3343
  80. package/lib/replay/rrweb-replay.js +3742 -3288
  81. package/lib/rrweb-all.js +6725 -6247
  82. package/lib/rrweb.js +6157 -5632
  83. package/package.json +14 -13
  84. package/typings/packer/base.d.ts +1 -1
  85. package/typings/plugins/console/record/index.d.ts +1 -1
  86. package/typings/plugins/console/record/stringify.d.ts +1 -1
  87. package/typings/plugins/sequential-id/record/index.d.ts +1 -1
  88. package/typings/plugins/sequential-id/replay/index.d.ts +1 -1
  89. package/typings/record/iframe-manager.d.ts +3 -3
  90. package/typings/record/index.d.ts +1 -1
  91. package/typings/record/mutation.d.ts +2 -1
  92. package/typings/record/observers/canvas/2d.d.ts +2 -1
  93. package/typings/record/observers/canvas/canvas-manager.d.ts +5 -2
  94. package/typings/record/observers/canvas/canvas.d.ts +1 -1
  95. package/typings/record/observers/canvas/serialize-args.d.ts +5 -5
  96. package/typings/record/observers/canvas/webgl.d.ts +2 -1
  97. package/typings/record/shadow-dom-manager.d.ts +2 -1
  98. package/typings/record/stylesheet-manager.d.ts +12 -0
  99. package/typings/record/workers/image-bitmap-data-url-worker.d.ts +5 -0
  100. package/typings/replay/canvas/2d.d.ts +3 -3
  101. package/typings/replay/canvas/deserialize-args.d.ts +7 -0
  102. package/typings/replay/canvas/index.d.ts +4 -3
  103. package/typings/replay/canvas/webgl.d.ts +3 -5
  104. package/typings/replay/index.d.ts +7 -10
  105. package/typings/types.d.ts +45 -17
  106. package/typings/utils.d.ts +17 -44
  107. package/dist/replay/rrweb-replay-unpack.min.css +0 -2
  108. package/dist/replay/rrweb-replay-unpack.min.css.map +0 -1
  109. package/dist/replay/rrweb-replay.min.css +0 -2
  110. package/dist/replay/rrweb-replay.min.css.map +0 -1
  111. package/dist/rrweb-all.min.css +0 -2
  112. package/dist/rrweb-all.min.css.map +0 -1
  113. package/dist/rrweb.min.css +0 -2
  114. package/dist/rrweb.min.css.map +0 -1
  115. package/es/rrweb/packages/rrweb/ext/tslib/tslib.es6.js +0 -78
  116. package/es/rrweb/packages/rrweb/src/replay/virtual-styles.js +0 -121
  117. package/typings/replay/virtual-styles.d.ts +0 -43
@@ -1,116 +1,123 @@
1
- import { __spreadArray, __read } from '../../../../ext/tslib/tslib.es6.js';
2
- import { encode } from '../../../../../../ext/base64-arraybuffer/dist/base64-arraybuffer.es5.js';
1
+ import { encode } from './../../../../../../ext/base64-arraybuffer/dist/base64-arraybuffer.es5.js';
3
2
 
4
- var webGLVarMap = new Map();
5
- function variableListFor(ctx, ctor) {
6
- var contextMap = webGLVarMap.get(ctx);
7
- if (!contextMap) {
8
- contextMap = new Map();
9
- webGLVarMap.set(ctx, contextMap);
10
- }
11
- if (!contextMap.has(ctor)) {
12
- contextMap.set(ctor, []);
13
- }
14
- return contextMap.get(ctor);
15
- }
16
- var saveWebGLVar = function (value, win, ctx) {
17
- if (!value ||
18
- !(isInstanceOfWebGLObject(value, win) || typeof value === 'object'))
19
- return;
20
- var name = value.constructor.name;
21
- var list = variableListFor(ctx, name);
22
- var index = list.indexOf(value);
23
- if (index === -1) {
24
- index = list.length;
25
- list.push(value);
26
- }
27
- return index;
28
- };
29
- function serializeArg(value, win, ctx) {
30
- if (value instanceof Array) {
31
- return value.map(function (arg) { return serializeArg(arg, win, ctx); });
32
- }
33
- else if (value === null) {
34
- return value;
35
- }
36
- else if (value instanceof Float32Array ||
37
- value instanceof Float64Array ||
38
- value instanceof Int32Array ||
39
- value instanceof Uint32Array ||
40
- value instanceof Uint8Array ||
41
- value instanceof Uint16Array ||
42
- value instanceof Int16Array ||
43
- value instanceof Int8Array ||
44
- value instanceof Uint8ClampedArray) {
45
- var name_1 = value.constructor.name;
46
- return {
47
- rr_type: name_1,
48
- args: [Object.values(value)],
49
- };
50
- }
51
- else if (value instanceof ArrayBuffer) {
52
- var name_2 = value.constructor.name;
53
- var base64 = encode(value);
54
- return {
55
- rr_type: name_2,
56
- base64: base64,
57
- };
58
- }
59
- else if (value instanceof DataView) {
60
- var name_3 = value.constructor.name;
61
- return {
62
- rr_type: name_3,
63
- args: [
64
- serializeArg(value.buffer, win, ctx),
65
- value.byteOffset,
66
- value.byteLength,
67
- ],
68
- };
69
- }
70
- else if (value instanceof HTMLImageElement) {
71
- var name_4 = value.constructor.name;
72
- var src = value.src;
73
- return {
74
- rr_type: name_4,
75
- src: src,
76
- };
77
- }
78
- else if (value instanceof ImageData) {
79
- var name_5 = value.constructor.name;
80
- return {
81
- rr_type: name_5,
82
- args: [serializeArg(value.data, win, ctx), value.width, value.height],
83
- };
84
- }
85
- else if (isInstanceOfWebGLObject(value, win) || typeof value === 'object') {
86
- var name_6 = value.constructor.name;
87
- var index = saveWebGLVar(value, win, ctx);
88
- return {
89
- rr_type: name_6,
90
- index: index,
91
- };
92
- }
93
- return value;
94
- }
95
- var serializeArgs = function (args, win, ctx) {
96
- return __spreadArray([], __read(args), false).map(function (arg) { return serializeArg(arg, win, ctx); });
97
- };
98
- var isInstanceOfWebGLObject = function (value, win) {
99
- var webGLConstructorNames = [
100
- 'WebGLActiveInfo',
101
- 'WebGLBuffer',
102
- 'WebGLFramebuffer',
103
- 'WebGLProgram',
104
- 'WebGLRenderbuffer',
105
- 'WebGLShader',
106
- 'WebGLShaderPrecisionFormat',
107
- 'WebGLTexture',
108
- 'WebGLUniformLocation',
109
- 'WebGLVertexArrayObject',
110
- 'WebGLVertexArrayObjectOES',
111
- ];
112
- var supportedWebGLConstructorNames = webGLConstructorNames.filter(function (name) { return typeof win[name] === 'function'; });
113
- return Boolean(supportedWebGLConstructorNames.find(function (name) { return value instanceof win[name]; }));
3
+ const canvasVarMap = new Map();
4
+ function variableListFor(ctx, ctor) {
5
+ let contextMap = canvasVarMap.get(ctx);
6
+ if (!contextMap) {
7
+ contextMap = new Map();
8
+ canvasVarMap.set(ctx, contextMap);
9
+ }
10
+ if (!contextMap.has(ctor)) {
11
+ contextMap.set(ctor, []);
12
+ }
13
+ return contextMap.get(ctor);
14
+ }
15
+ const saveWebGLVar = (value, win, ctx) => {
16
+ if (!value ||
17
+ !(isInstanceOfWebGLObject(value, win) || typeof value === 'object'))
18
+ return;
19
+ const name = value.constructor.name;
20
+ const list = variableListFor(ctx, name);
21
+ let index = list.indexOf(value);
22
+ if (index === -1) {
23
+ index = list.length;
24
+ list.push(value);
25
+ }
26
+ return index;
27
+ };
28
+ function serializeArg(value, win, ctx) {
29
+ if (value instanceof Array) {
30
+ return value.map((arg) => serializeArg(arg, win, ctx));
31
+ }
32
+ else if (value === null) {
33
+ return value;
34
+ }
35
+ else if (value instanceof Float32Array ||
36
+ value instanceof Float64Array ||
37
+ value instanceof Int32Array ||
38
+ value instanceof Uint32Array ||
39
+ value instanceof Uint8Array ||
40
+ value instanceof Uint16Array ||
41
+ value instanceof Int16Array ||
42
+ value instanceof Int8Array ||
43
+ value instanceof Uint8ClampedArray) {
44
+ const name = value.constructor.name;
45
+ return {
46
+ rr_type: name,
47
+ args: [Object.values(value)],
48
+ };
49
+ }
50
+ else if (value instanceof ArrayBuffer) {
51
+ const name = value.constructor.name;
52
+ const base64 = encode(value);
53
+ return {
54
+ rr_type: name,
55
+ base64,
56
+ };
57
+ }
58
+ else if (value instanceof DataView) {
59
+ const name = value.constructor.name;
60
+ return {
61
+ rr_type: name,
62
+ args: [
63
+ serializeArg(value.buffer, win, ctx),
64
+ value.byteOffset,
65
+ value.byteLength,
66
+ ],
67
+ };
68
+ }
69
+ else if (value instanceof HTMLImageElement) {
70
+ const name = value.constructor.name;
71
+ const { src } = value;
72
+ return {
73
+ rr_type: name,
74
+ src,
75
+ };
76
+ }
77
+ else if (value instanceof HTMLCanvasElement) {
78
+ const name = 'HTMLImageElement';
79
+ const src = value.toDataURL();
80
+ return {
81
+ rr_type: name,
82
+ src,
83
+ };
84
+ }
85
+ else if (value instanceof ImageData) {
86
+ const name = value.constructor.name;
87
+ return {
88
+ rr_type: name,
89
+ args: [serializeArg(value.data, win, ctx), value.width, value.height],
90
+ };
91
+ }
92
+ else if (isInstanceOfWebGLObject(value, win) || typeof value === 'object') {
93
+ const name = value.constructor.name;
94
+ const index = saveWebGLVar(value, win, ctx);
95
+ return {
96
+ rr_type: name,
97
+ index: index,
98
+ };
99
+ }
100
+ return value;
101
+ }
102
+ const serializeArgs = (args, win, ctx) => {
103
+ return [...args].map((arg) => serializeArg(arg, win, ctx));
104
+ };
105
+ const isInstanceOfWebGLObject = (value, win) => {
106
+ const webGLConstructorNames = [
107
+ 'WebGLActiveInfo',
108
+ 'WebGLBuffer',
109
+ 'WebGLFramebuffer',
110
+ 'WebGLProgram',
111
+ 'WebGLRenderbuffer',
112
+ 'WebGLShader',
113
+ 'WebGLShaderPrecisionFormat',
114
+ 'WebGLTexture',
115
+ 'WebGLUniformLocation',
116
+ 'WebGLVertexArrayObject',
117
+ 'WebGLVertexArrayObjectOES',
118
+ ];
119
+ const supportedWebGLConstructorNames = webGLConstructorNames.filter((name) => typeof win[name] === 'function');
120
+ return Boolean(supportedWebGLConstructorNames.find((name) => value instanceof win[name]));
114
121
  };
115
122
 
116
123
  export { isInstanceOfWebGLObject, saveWebGLVar, serializeArg, serializeArgs, variableListFor };
@@ -1,78 +1,59 @@
1
- import { __spreadArray, __read, __values } from '../../../../ext/tslib/tslib.es6.js';
2
1
  import { CanvasContext } from '../../../types.js';
3
2
  import { patch, isBlocked, hookSetter } from '../../../utils.js';
4
3
  import { saveWebGLVar, serializeArgs } from './serialize-args.js';
5
4
 
6
- function patchGLPrototype(prototype, type, cb, blockClass, mirror, win) {
7
- var e_1, _a;
8
- var handlers = [];
9
- var props = Object.getOwnPropertyNames(prototype);
10
- var _loop_1 = function (prop) {
11
- try {
12
- if (typeof prototype[prop] !== 'function') {
13
- return "continue";
14
- }
15
- var restoreHandler = patch(prototype, prop, function (original) {
16
- return function () {
17
- var args = [];
18
- for (var _i = 0; _i < arguments.length; _i++) {
19
- args[_i] = arguments[_i];
20
- }
21
- var result = original.apply(this, args);
22
- saveWebGLVar(result, win, prototype);
23
- if (!isBlocked(this.canvas, blockClass)) {
24
- var id = mirror.getId(this.canvas);
25
- var recordArgs = serializeArgs(__spreadArray([], __read(args), false), win, prototype);
26
- var mutation = {
27
- type: type,
28
- property: prop,
29
- args: recordArgs,
30
- };
31
- cb(this.canvas, mutation);
32
- }
33
- return result;
34
- };
35
- });
36
- handlers.push(restoreHandler);
37
- }
38
- catch (_b) {
39
- var hookHandler = hookSetter(prototype, prop, {
40
- set: function (v) {
41
- cb(this.canvas, {
42
- type: type,
43
- property: prop,
44
- args: [v],
45
- setter: true,
46
- });
47
- },
48
- });
49
- handlers.push(hookHandler);
50
- }
51
- };
52
- try {
53
- for (var props_1 = __values(props), props_1_1 = props_1.next(); !props_1_1.done; props_1_1 = props_1.next()) {
54
- var prop = props_1_1.value;
55
- _loop_1(prop);
56
- }
57
- }
58
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
59
- finally {
60
- try {
61
- if (props_1_1 && !props_1_1.done && (_a = props_1.return)) _a.call(props_1);
62
- }
63
- finally { if (e_1) throw e_1.error; }
64
- }
65
- return handlers;
66
- }
67
- function initCanvasWebGLMutationObserver(cb, win, blockClass, mirror) {
68
- var handlers = [];
69
- handlers.push.apply(handlers, __spreadArray([], __read(patchGLPrototype(win.WebGLRenderingContext.prototype, CanvasContext.WebGL, cb, blockClass, mirror, win)), false));
70
- if (typeof win.WebGL2RenderingContext !== 'undefined') {
71
- handlers.push.apply(handlers, __spreadArray([], __read(patchGLPrototype(win.WebGL2RenderingContext.prototype, CanvasContext.WebGL2, cb, blockClass, mirror, win)), false));
72
- }
73
- return function () {
74
- handlers.forEach(function (h) { return h(); });
75
- };
5
+ function patchGLPrototype(prototype, type, cb, blockClass, mirror, win) {
6
+ const handlers = [];
7
+ const props = Object.getOwnPropertyNames(prototype);
8
+ for (const prop of props) {
9
+ try {
10
+ if (typeof prototype[prop] !== 'function') {
11
+ continue;
12
+ }
13
+ const restoreHandler = patch(prototype, prop, function (original) {
14
+ return function (...args) {
15
+ const result = original.apply(this, args);
16
+ saveWebGLVar(result, win, prototype);
17
+ if (!isBlocked(this.canvas, blockClass)) {
18
+ const id = mirror.getId(this.canvas);
19
+ const recordArgs = serializeArgs([...args], win, prototype);
20
+ const mutation = {
21
+ type,
22
+ property: prop,
23
+ args: recordArgs,
24
+ };
25
+ cb(this.canvas, mutation);
26
+ }
27
+ return result;
28
+ };
29
+ });
30
+ handlers.push(restoreHandler);
31
+ }
32
+ catch (_a) {
33
+ const hookHandler = hookSetter(prototype, prop, {
34
+ set(v) {
35
+ cb(this.canvas, {
36
+ type,
37
+ property: prop,
38
+ args: [v],
39
+ setter: true,
40
+ });
41
+ },
42
+ });
43
+ handlers.push(hookHandler);
44
+ }
45
+ }
46
+ return handlers;
47
+ }
48
+ function initCanvasWebGLMutationObserver(cb, win, blockClass, mirror) {
49
+ const handlers = [];
50
+ handlers.push(...patchGLPrototype(win.WebGLRenderingContext.prototype, CanvasContext.WebGL, cb, blockClass, mirror, win));
51
+ if (typeof win.WebGL2RenderingContext !== 'undefined') {
52
+ handlers.push(...patchGLPrototype(win.WebGL2RenderingContext.prototype, CanvasContext.WebGL2, cb, blockClass, mirror, win));
53
+ }
54
+ return () => {
55
+ handlers.forEach((h) => h());
56
+ };
76
57
  }
77
58
 
78
- export default initCanvasWebGLMutationObserver;
59
+ export { initCanvasWebGLMutationObserver as default };
@@ -1,45 +1,43 @@
1
- import { __assign } from '../../ext/tslib/tslib.es6.js';
2
1
  import { initMutationObserver, initScrollObserver } from './observer.js';
3
2
  import { patch } from '../utils.js';
4
3
 
5
- var ShadowDomManager = (function () {
6
- function ShadowDomManager(options) {
7
- this.restorePatches = [];
8
- this.mutationCb = options.mutationCb;
9
- this.scrollCb = options.scrollCb;
10
- this.bypassOptions = options.bypassOptions;
11
- this.mirror = options.mirror;
12
- var manager = this;
13
- this.restorePatches.push(patch(HTMLElement.prototype, 'attachShadow', function (original) {
14
- return function () {
15
- var shadowRoot = original.apply(this, arguments);
16
- if (this.shadowRoot)
17
- manager.addShadowRoot(this.shadowRoot, this.ownerDocument);
18
- return shadowRoot;
19
- };
20
- }));
21
- }
22
- ShadowDomManager.prototype.addShadowRoot = function (shadowRoot, doc) {
23
- initMutationObserver(__assign(__assign({}, this.bypassOptions), { doc: doc, mutationCb: this.mutationCb, mirror: this.mirror, shadowDomManager: this }), shadowRoot);
24
- initScrollObserver(__assign(__assign({}, this.bypassOptions), { scrollCb: this.scrollCb, doc: shadowRoot, mirror: this.mirror }));
25
- };
26
- ShadowDomManager.prototype.observeAttachShadow = function (iframeElement) {
27
- if (iframeElement.contentWindow) {
28
- var manager_1 = this;
29
- this.restorePatches.push(patch(iframeElement.contentWindow.HTMLElement.prototype, 'attachShadow', function (original) {
30
- return function () {
31
- var shadowRoot = original.apply(this, arguments);
32
- if (this.shadowRoot)
33
- manager_1.addShadowRoot(this.shadowRoot, iframeElement.contentDocument);
34
- return shadowRoot;
35
- };
36
- }));
37
- }
38
- };
39
- ShadowDomManager.prototype.reset = function () {
40
- this.restorePatches.forEach(function (restorePatch) { return restorePatch(); });
41
- };
42
- return ShadowDomManager;
43
- }());
4
+ class ShadowDomManager {
5
+ constructor(options) {
6
+ this.restorePatches = [];
7
+ this.mutationCb = options.mutationCb;
8
+ this.scrollCb = options.scrollCb;
9
+ this.bypassOptions = options.bypassOptions;
10
+ this.mirror = options.mirror;
11
+ const manager = this;
12
+ this.restorePatches.push(patch(HTMLElement.prototype, 'attachShadow', function (original) {
13
+ return function () {
14
+ const shadowRoot = original.apply(this, arguments);
15
+ if (this.shadowRoot)
16
+ manager.addShadowRoot(this.shadowRoot, this.ownerDocument);
17
+ return shadowRoot;
18
+ };
19
+ }));
20
+ }
21
+ addShadowRoot(shadowRoot, doc) {
22
+ initMutationObserver(Object.assign(Object.assign({}, this.bypassOptions), { doc, mutationCb: this.mutationCb, mirror: this.mirror, shadowDomManager: this }), shadowRoot);
23
+ initScrollObserver(Object.assign(Object.assign({}, this.bypassOptions), { scrollCb: this.scrollCb, doc: shadowRoot, mirror: this.mirror }));
24
+ }
25
+ observeAttachShadow(iframeElement) {
26
+ if (iframeElement.contentWindow) {
27
+ const manager = this;
28
+ this.restorePatches.push(patch(iframeElement.contentWindow.HTMLElement.prototype, 'attachShadow', function (original) {
29
+ return function () {
30
+ const shadowRoot = original.apply(this, arguments);
31
+ if (this.shadowRoot)
32
+ manager.addShadowRoot(this.shadowRoot, iframeElement.contentDocument);
33
+ return shadowRoot;
34
+ };
35
+ }));
36
+ }
37
+ }
38
+ reset() {
39
+ this.restorePatches.forEach((restorePatch) => restorePatch());
40
+ }
41
+ }
44
42
 
45
43
  export { ShadowDomManager };
@@ -0,0 +1,31 @@
1
+ class StylesheetManager {
2
+ constructor(options) {
3
+ this.trackedStylesheets = new WeakSet();
4
+ this.mutationCb = options.mutationCb;
5
+ }
6
+ addStylesheet(linkEl) {
7
+ if (this.trackedStylesheets.has(linkEl))
8
+ return;
9
+ this.trackedStylesheets.add(linkEl);
10
+ this.trackStylesheet(linkEl);
11
+ }
12
+ trackStylesheet(linkEl) {
13
+ }
14
+ attachStylesheet(linkEl, childSn, mirror) {
15
+ this.mutationCb({
16
+ adds: [
17
+ {
18
+ parentId: mirror.getId(linkEl),
19
+ nextId: null,
20
+ node: childSn,
21
+ },
22
+ ],
23
+ removes: [],
24
+ texts: [],
25
+ attributes: [],
26
+ });
27
+ this.addStylesheet(linkEl);
28
+ }
29
+ }
30
+
31
+ export { StylesheetManager };
@@ -1,25 +1,29 @@
1
- function canvasMutation(_a) {
2
- var event = _a.event, mutation = _a.mutation, target = _a.target, imageMap = _a.imageMap, errorHandler = _a.errorHandler;
3
- try {
4
- var ctx = target.getContext('2d');
5
- if (mutation.setter) {
6
- ctx[mutation.property] = mutation.args[0];
7
- return;
8
- }
9
- var original = ctx[mutation.property];
10
- if (mutation.property === 'drawImage' &&
11
- typeof mutation.args[0] === 'string') {
12
- var image = imageMap.get(event);
13
- mutation.args[0] = image;
14
- original.apply(ctx, mutation.args);
15
- }
16
- else {
17
- original.apply(ctx, mutation.args);
18
- }
19
- }
20
- catch (error) {
21
- errorHandler(mutation, error);
22
- }
1
+ import { __awaiter } from './../../../../../ext/tslib/tslib.es6.js';
2
+ import { deserializeArg } from './deserialize-args.js';
3
+
4
+ function canvasMutation({ event, mutation, target, imageMap, errorHandler, }) {
5
+ return __awaiter(this, void 0, void 0, function* () {
6
+ try {
7
+ const ctx = target.getContext('2d');
8
+ if (mutation.setter) {
9
+ ctx[mutation.property] = mutation.args[0];
10
+ return;
11
+ }
12
+ const original = ctx[mutation.property];
13
+ if (mutation.property === 'drawImage' &&
14
+ typeof mutation.args[0] === 'string') {
15
+ const image = imageMap.get(event);
16
+ original.apply(ctx, mutation.args);
17
+ }
18
+ else {
19
+ const args = yield Promise.all(mutation.args.map(deserializeArg(imageMap, ctx)));
20
+ original.apply(ctx, args);
21
+ }
22
+ }
23
+ catch (error) {
24
+ errorHandler(mutation, error);
25
+ }
26
+ });
23
27
  }
24
28
 
25
- export default canvasMutation;
29
+ export { canvasMutation as default };
@@ -0,0 +1,67 @@
1
+ import { __awaiter } from './../../../../../ext/tslib/tslib.es6.js';
2
+ import { decode } from './../../../../../ext/base64-arraybuffer/dist/base64-arraybuffer.es5.js';
3
+
4
+ const webGLVarMap = new Map();
5
+ function variableListFor(ctx, ctor) {
6
+ let contextMap = webGLVarMap.get(ctx);
7
+ if (!contextMap) {
8
+ contextMap = new Map();
9
+ webGLVarMap.set(ctx, contextMap);
10
+ }
11
+ if (!contextMap.has(ctor)) {
12
+ contextMap.set(ctor, []);
13
+ }
14
+ return contextMap.get(ctor);
15
+ }
16
+ function deserializeArg(imageMap, ctx, preload) {
17
+ return (arg) => __awaiter(this, void 0, void 0, function* () {
18
+ if (arg && typeof arg === 'object' && 'rr_type' in arg) {
19
+ if (preload)
20
+ preload.isUnchanged = false;
21
+ if (arg.rr_type === 'ImageBitmap' && 'args' in arg) {
22
+ const args = yield deserializeArg(imageMap, ctx, preload)(arg.args);
23
+ return yield createImageBitmap.apply(null, args);
24
+ }
25
+ else if ('index' in arg) {
26
+ if (preload || ctx === null)
27
+ return arg;
28
+ const { rr_type: name, index } = arg;
29
+ return variableListFor(ctx, name)[index];
30
+ }
31
+ else if ('args' in arg) {
32
+ const { rr_type: name, args } = arg;
33
+ const ctor = window[name];
34
+ return new ctor(...(yield Promise.all(args.map(deserializeArg(imageMap, ctx, preload)))));
35
+ }
36
+ else if ('base64' in arg) {
37
+ return decode(arg.base64);
38
+ }
39
+ else if ('src' in arg) {
40
+ const image = imageMap.get(arg.src);
41
+ if (image) {
42
+ return image;
43
+ }
44
+ else {
45
+ const image = new Image();
46
+ image.src = arg.src;
47
+ imageMap.set(arg.src, image);
48
+ return image;
49
+ }
50
+ }
51
+ else if ('data' in arg && arg.rr_type === 'Blob') {
52
+ const blobContents = yield Promise.all(arg.data.map(deserializeArg(imageMap, ctx, preload)));
53
+ const blob = new Blob(blobContents, {
54
+ type: arg.type,
55
+ });
56
+ return blob;
57
+ }
58
+ }
59
+ else if (Array.isArray(arg)) {
60
+ const result = yield Promise.all(arg.map(deserializeArg(imageMap, ctx, preload)));
61
+ return result;
62
+ }
63
+ return arg;
64
+ });
65
+ }
66
+
67
+ export { deserializeArg, variableListFor };