@mpxjs/webpack-plugin 2.9.67 → 2.9.69

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 (48) hide show
  1. package/lib/index.js +13 -8
  2. package/lib/platform/template/wx/component-config/canvas.js +8 -0
  3. package/lib/platform/template/wx/component-config/unsupported.js +1 -1
  4. package/lib/react/processStyles.js +14 -4
  5. package/lib/resolver/AddModePlugin.js +8 -8
  6. package/lib/runtime/components/react/context.ts +2 -0
  7. package/lib/runtime/components/react/dist/context.js +1 -0
  8. package/lib/runtime/components/react/dist/getInnerListeners.js +3 -12
  9. package/lib/runtime/components/react/dist/mpx-button.jsx +43 -8
  10. package/lib/runtime/components/react/dist/mpx-canvas/Bus.js +60 -0
  11. package/lib/runtime/components/react/dist/mpx-canvas/CanvasGradient.js +15 -0
  12. package/lib/runtime/components/react/dist/mpx-canvas/CanvasRenderingContext2D.js +84 -0
  13. package/lib/runtime/components/react/dist/mpx-canvas/Image.js +87 -0
  14. package/lib/runtime/components/react/dist/mpx-canvas/ImageData.js +15 -0
  15. package/lib/runtime/components/react/dist/mpx-canvas/constructorsRegistry.js +28 -0
  16. package/lib/runtime/components/react/dist/mpx-canvas/html.js +343 -0
  17. package/lib/runtime/components/react/dist/mpx-canvas/index.jsx +214 -0
  18. package/lib/runtime/components/react/dist/mpx-canvas/utils.jsx +89 -0
  19. package/lib/runtime/components/react/dist/mpx-picker-view-column.jsx +143 -84
  20. package/lib/runtime/components/react/dist/mpx-picker-view.jsx +69 -113
  21. package/lib/runtime/components/react/dist/mpx-view.jsx +45 -26
  22. package/lib/runtime/components/react/dist/mpx-web-view.jsx +19 -5
  23. package/lib/runtime/components/react/dist/pickerFaces.js +75 -0
  24. package/lib/runtime/components/react/dist/pickerOverlay.jsx +21 -0
  25. package/lib/runtime/components/react/dist/utils.jsx +54 -3
  26. package/lib/runtime/components/react/getInnerListeners.ts +3 -17
  27. package/lib/runtime/components/react/mpx-button.tsx +41 -8
  28. package/lib/runtime/components/react/mpx-canvas/Bus.ts +70 -0
  29. package/lib/runtime/components/react/mpx-canvas/CanvasGradient.ts +18 -0
  30. package/lib/runtime/components/react/mpx-canvas/CanvasRenderingContext2D.ts +87 -0
  31. package/lib/runtime/components/react/mpx-canvas/Image.ts +102 -0
  32. package/lib/runtime/components/react/mpx-canvas/ImageData.ts +23 -0
  33. package/lib/runtime/components/react/mpx-canvas/constructorsRegistry.ts +38 -0
  34. package/lib/runtime/components/react/mpx-canvas/html.ts +343 -0
  35. package/lib/runtime/components/react/mpx-canvas/index.tsx +302 -0
  36. package/lib/runtime/components/react/mpx-canvas/utils.tsx +150 -0
  37. package/lib/runtime/components/react/mpx-picker-view-column.tsx +232 -103
  38. package/lib/runtime/components/react/mpx-picker-view.tsx +126 -122
  39. package/lib/runtime/components/react/mpx-view.tsx +57 -27
  40. package/lib/runtime/components/react/mpx-web-view.tsx +22 -5
  41. package/lib/runtime/components/react/pickerFaces.ts +104 -0
  42. package/lib/runtime/components/react/pickerOverlay.tsx +32 -0
  43. package/lib/runtime/components/react/types/common.ts +2 -0
  44. package/lib/runtime/components/react/types/global.d.ts +2 -0
  45. package/lib/runtime/components/react/utils.tsx +78 -7
  46. package/lib/template-compiler/compiler.js +3 -2
  47. package/lib/template-compiler/gen-node-react.js +2 -2
  48. package/package.json +5 -4
package/lib/index.js CHANGED
@@ -348,14 +348,19 @@ class MpxWebpackPlugin {
348
348
  compiler.options.node.global = true
349
349
  }
350
350
 
351
- let addModePlugin
352
- if (['android', 'harmony'].includes(this.options.mode)) {
353
- // 'android' | 'harmony' 下 使用mode = 'ios' 进行兼容兜底
354
- addModePlugin = new AddModePlugin('before-file', this.options.mode, this.options.fileConditionRules, 'file', 'ios')
355
- } else {
356
- addModePlugin = new AddModePlugin('before-file', this.options.mode, this.options.fileConditionRules, 'file')
351
+ const addModeOptions = {
352
+ fileConditionRules: this.options.fileConditionRules
357
353
  }
358
-
354
+ const mode = this.options.mode
355
+ if (mode === 'web' || mode === 'ios' || mode === 'android' || mode === 'harmony') {
356
+ // 'web' | 'ios' | 'android' | 'harmony' 下,使用implicitMode强制进行平台转换
357
+ addModeOptions.implicitMode = true
358
+ }
359
+ if (mode === 'android' || mode === 'harmony') {
360
+ // 'android' | 'harmony' 下,使用 mode = 'ios' 进行兼容兜底
361
+ addModeOptions.defaultMode = 'ios'
362
+ }
363
+ const addModePlugin = new AddModePlugin('before-file', this.options.mode, addModeOptions, 'file')
359
364
  const addEnvPlugin = new AddEnvPlugin('before-file', this.options.env, this.options.fileConditionRules, 'file')
360
365
  const packageEntryPlugin = new PackageEntryPlugin('before-file', this.options.miniNpmPackages, 'file')
361
366
  const dynamicPlugin = new DynamicPlugin('result', this.options.dynamicComponentRules)
@@ -775,7 +780,7 @@ class MpxWebpackPlugin {
775
780
  const hash = mpx.pathHash(resourcePath)
776
781
  const customOutputPath = this.options.customOutputPath
777
782
  if (conflictPath) return conflictPath.replace(/(\.[^\\/]+)?$/, match => hash + match)
778
- if (typeof customOutputPath === 'function') return customOutputPath(type, name, hash, ext).replace(/^\//, '')
783
+ if (typeof customOutputPath === 'function') return customOutputPath(type, name, hash, ext, resourcePath).replace(/^\//, '')
779
784
  if (type === 'component' || type === 'page') return path.join(type + 's', name + hash, 'index' + ext)
780
785
  return path.join(type, name + hash + ext)
781
786
  },
@@ -8,6 +8,14 @@ module.exports = function ({ print }) {
8
8
  const qaEventLog = print({ platform: 'qa', tag: TAG_NAME, isError: false, type: 'event' })
9
9
  return {
10
10
  test: TAG_NAME,
11
+ android (tag, { el }) {
12
+ el.isBuiltIn = true
13
+ return 'mpx-canvas'
14
+ },
15
+ ios (tag, { el }) {
16
+ el.isBuiltIn = true
17
+ return 'mpx-canvas'
18
+ },
11
19
  props: [
12
20
  {
13
21
  test: /^canvas-id$/,
@@ -11,7 +11,7 @@ const JD_UNSUPPORTED_TAG_NAME_ARR = ['functional-page-navigator', 'live-pusher',
11
11
  // 快应用不支持的标签集合
12
12
  const QA_UNSUPPORTED_TAG_NAME_ARR = ['movable-view', 'movable-area', 'open-data', 'official-account', 'editor', 'functional-page-navigator', 'live-player', 'live-pusher', 'ad', 'cover-image']
13
13
  // RN不支持的标签集合
14
- const RN_UNSUPPORTED_TAG_NAME_ARR = ['open-data', 'official-account', 'editor', 'functional-page-navigator', 'live-player', 'live-pusher', 'ad', 'progress', 'rich-text', 'slider', 'audio', 'camera', 'video', 'canvas', 'match-media', 'page-container', 'editor', 'keyboard-accessory', 'map']
14
+ const RN_UNSUPPORTED_TAG_NAME_ARR = ['open-data', 'official-account', 'editor', 'functional-page-navigator', 'live-player', 'live-pusher', 'ad', 'progress', 'rich-text', 'slider', 'audio', 'camera', 'video', 'match-media', 'page-container', 'editor', 'keyboard-accessory', 'map']
15
15
 
16
16
  /**
17
17
  * @param {function(object): function} print
@@ -56,13 +56,23 @@ module.exports = function (styles, {
56
56
  error
57
57
  })
58
58
  if (ctorType === 'app') {
59
- output += `global.__getAppClassMap = function() {
60
- return ${shallowStringify(classMap)};
59
+ output += `
60
+ let __appClassMap
61
+ global.__getAppClassMap = function() {
62
+ if(!__appClassMap) {
63
+ __appClassMap = ${shallowStringify(classMap)};
64
+ }
65
+ return __appClassMap;
61
66
  };\n`
62
67
  } else {
63
- output += `global.currentInject.injectMethods = {
68
+ output += `
69
+ let __classMap
70
+ global.currentInject.injectMethods = {
64
71
  __getClassMap: function() {
65
- return ${shallowStringify(classMap)};
72
+ if(!__classMap) {
73
+ __classMap = ${shallowStringify(classMap)};
74
+ }
75
+ return __classMap;
66
76
  }
67
77
  };\n`
68
78
  }
@@ -6,17 +6,17 @@ const addInfix = require('../utils/add-infix')
6
6
  const { JSON_JS_EXT } = require('../utils/const')
7
7
 
8
8
  module.exports = class AddModePlugin {
9
- constructor (source, mode, fileConditionRules, target, defaultMode) {
9
+ constructor (source, mode, options, target) {
10
10
  this.source = source
11
11
  this.target = target
12
12
  this.mode = mode
13
- this.fileConditionRules = fileConditionRules
14
- this.defaultMode = defaultMode
13
+ this.options = options
15
14
  }
16
15
 
17
16
  apply (resolver) {
18
17
  const target = resolver.ensureHook(this.target)
19
- const { defaultMode, mode } = this
18
+ const { options = {}, mode } = this
19
+ const { defaultMode, fileConditionRules, implicitMode } = options
20
20
  resolver.getHook(this.source).tapAsync('AddModePlugin', (request, resolveContext, callback) => {
21
21
  if (request.mode || request.env) {
22
22
  return callback()
@@ -32,20 +32,20 @@ module.exports = class AddModePlugin {
32
32
  extname = path.extname(resourcePath)
33
33
  }
34
34
  // 当前资源没有后缀名或者路径不符合fileConditionRules规则时,直接返回
35
- if (!extname || !matchCondition(resourcePath, this.fileConditionRules)) return callback()
35
+ if (!extname || !matchCondition(resourcePath, fileConditionRules)) return callback()
36
36
  const queryObj = parseQuery(request.query || '?')
37
37
  const queryInfix = queryObj.infix
38
- queryObj.mode = mode
38
+ if (!implicitMode) queryObj.mode = mode
39
39
  queryObj.infix = `${queryInfix || ''}.${mode}`
40
40
  obj.query = stringifyQuery(queryObj)
41
41
  obj.path = addInfix(resourcePath, mode, extname)
42
42
  obj.relativePath = request.relativePath && addInfix(request.relativePath, mode, extname)
43
43
  resolver.doResolve(target, Object.assign({}, request, obj), 'add mode: ' + mode, resolveContext, (err, result) => {
44
- if (this.defaultMode && !result) {
44
+ if (defaultMode && !result) {
45
45
  queryObj.infix = `${queryInfix || ''}.${defaultMode}`
46
46
  obj.query = stringifyQuery(queryObj)
47
47
  obj.path = addInfix(resourcePath, defaultMode, extname)
48
- resolver.doResolve(target, Object.assign({}, request, obj), 'add mode: ' + this.defaultMode, resolveContext, (err, result) => {
48
+ resolver.doResolve(target, Object.assign({}, request, obj), 'add mode: ' + defaultMode, resolveContext, (err, result) => {
49
49
  callback(err, result)
50
50
  })
51
51
  return
@@ -46,3 +46,5 @@ export const PickerContext = createContext(null)
46
46
  export const VarContext = createContext({})
47
47
 
48
48
  export const IntersectionObserverContext = createContext<IntersectionObserver | null>(null)
49
+
50
+ export const RouteContext = createContext<number | null>(null)
@@ -7,3 +7,4 @@ export const LabelContext = createContext(null);
7
7
  export const PickerContext = createContext(null);
8
8
  export const VarContext = createContext({});
9
9
  export const IntersectionObserverContext = createContext(null);
10
+ export const RouteContext = createContext(null);
@@ -1,4 +1,5 @@
1
1
  import { useRef } from 'react';
2
+ import { collectDataset } from '@mpxjs/utils';
2
3
  import { omit } from './utils';
3
4
  import eventConfigMap from './event.config';
4
5
  const getTouchEvent = (type, event, props, config) => {
@@ -13,7 +14,7 @@ const getTouchEvent = (type, event, props, config) => {
13
14
  currentTarget: {
14
15
  ...(event.currentTarget || {}),
15
16
  id: id || '',
16
- dataset: getDataSet(props),
17
+ dataset: collectDataset(props),
17
18
  offsetLeft: layoutRef?.current?.offsetLeft || 0,
18
19
  offsetTop: layoutRef?.current?.offsetTop || 0
19
20
  },
@@ -44,16 +45,6 @@ const getTouchEvent = (type, event, props, config) => {
44
45
  preventDefault: event.preventDefault
45
46
  };
46
47
  };
47
- export const getDataSet = (props) => {
48
- const result = {};
49
- for (const key in props) {
50
- if (key.indexOf('data-') === 0) {
51
- const newKey = key.substr(5);
52
- result[newKey] = props[key];
53
- }
54
- }
55
- return result;
56
- };
57
48
  export const getCustomEvent = (type = '', oe = {}, { detail = {}, layoutRef }, props = {}) => {
58
49
  return {
59
50
  ...oe,
@@ -62,7 +53,7 @@ export const getCustomEvent = (type = '', oe = {}, { detail = {}, layoutRef }, p
62
53
  target: {
63
54
  ...(oe.target || {}),
64
55
  id: props.id || '',
65
- dataset: getDataSet(props),
56
+ dataset: collectDataset(props),
66
57
  offsetLeft: layoutRef?.current?.offsetLeft || 0,
67
58
  offsetTop: layoutRef?.current?.offsetTop || 0
68
59
  },
@@ -37,10 +37,10 @@
37
37
  import { useEffect, useRef, useState, forwardRef, useContext } from 'react';
38
38
  import { View, StyleSheet, Animated, Easing } from 'react-native';
39
39
  import { warn } from '@mpxjs/utils';
40
- import { splitProps, splitStyle, useLayout, useTransformStyle, wrapChildren } from './utils';
40
+ import { getCurrentPage, splitProps, splitStyle, useLayout, useTransformStyle, wrapChildren } from './utils';
41
41
  import useInnerProps, { getCustomEvent } from './getInnerListeners';
42
42
  import useNodesRef from './useNodesRef';
43
- import { FormContext } from './context';
43
+ import { RouteContext, FormContext } from './context';
44
44
  const LOADING_IMAGE_URI = 'data:image/png;base64,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';
45
45
  const TypeColorMap = {
46
46
  default: ['#F8F8F8', '#DEDEDE', '35,35,35', '#F7F7F7'],
@@ -78,6 +78,8 @@ const styles = StyleSheet.create({
78
78
  }
79
79
  });
80
80
  const getOpenTypeEvent = (openType) => {
81
+ if (!openType)
82
+ return;
81
83
  if (!global.__mpx?.config?.rnConfig) {
82
84
  warn('Environment not supported');
83
85
  return;
@@ -94,6 +96,11 @@ const getOpenTypeEvent = (openType) => {
94
96
  }
95
97
  return event;
96
98
  };
99
+ const timer = (data, time = 3000) => new Promise((resolve) => {
100
+ setTimeout(() => {
101
+ resolve(data);
102
+ }, time);
103
+ });
97
104
  const Loading = ({ alone = false }) => {
98
105
  const image = useRef(new Animated.Value(0)).current;
99
106
  const rotate = image.interpolate({
@@ -123,6 +130,7 @@ const Loading = ({ alone = false }) => {
123
130
  const Button = forwardRef((buttonProps, ref) => {
124
131
  const { textProps, innerProps: props = {} } = splitProps(buttonProps);
125
132
  const { size = 'default', type = 'default', plain = false, disabled = false, loading = false, 'hover-class': hoverClass, 'hover-style': hoverStyle = {}, 'hover-start-time': hoverStartTime = 20, 'hover-stay-time': hoverStayTime = 70, 'open-type': openType, 'form-type': formType, 'enable-var': enableVar, 'external-var-context': externalVarContext, 'parent-font-size': parentFontSize, 'parent-width': parentWidth, 'parent-height': parentHeight, style = {}, children, bindgetuserinfo, bindtap, bindtouchstart, bindtouchend } = props;
133
+ const pageId = useContext(RouteContext);
126
134
  const formContext = useContext(FormContext);
127
135
  let submitFn;
128
136
  let resetFn;
@@ -187,16 +195,43 @@ const Button = forwardRef((buttonProps, ref) => {
187
195
  warn('Button does not support background image-related styles!');
188
196
  }
189
197
  const handleOpenTypeEvent = (evt) => {
190
- if (!openType)
191
- return;
192
198
  const handleEvent = getOpenTypeEvent(openType);
199
+ if (!handleEvent)
200
+ return;
193
201
  if (openType === 'share') {
194
- handleEvent && handleEvent({
202
+ const currentPage = getCurrentPage(pageId);
203
+ const event = {
195
204
  from: 'button',
196
- target: getCustomEvent('tap', evt, { layoutRef }, props).target
197
- });
205
+ target: getCustomEvent('tap', evt, { layoutRef }, props).target,
206
+ webViewUrl: currentPage?.__webViewUrl
207
+ };
208
+ if (currentPage) {
209
+ const defaultMessage = {
210
+ title: global.__mpx.config.rnConfig.projectName || 'AwesomeProject',
211
+ path: currentPage.route || ''
212
+ };
213
+ if (currentPage.onShareAppMessage) {
214
+ const { promise, ...message } = currentPage.onShareAppMessage(event) || {};
215
+ if (promise) {
216
+ Promise.race([Promise.resolve(promise), timer(message)])
217
+ .then((msg) => {
218
+ handleEvent(Object.assign({}, defaultMessage, msg));
219
+ });
220
+ }
221
+ else {
222
+ handleEvent(Object.assign({}, defaultMessage, message));
223
+ }
224
+ }
225
+ else {
226
+ handleEvent(defaultMessage);
227
+ }
228
+ }
229
+ else {
230
+ warn('Current page not found');
231
+ // Todo handleEvent(event)
232
+ }
198
233
  }
199
- if (openType === 'getUserInfo' && handleEvent && bindgetuserinfo) {
234
+ if (openType === 'getUserInfo' && bindgetuserinfo) {
200
235
  Promise.resolve(handleEvent)
201
236
  .then((userInfo) => {
202
237
  if (typeof userInfo === 'object') {
@@ -0,0 +1,60 @@
1
+ import { warn } from '@mpxjs/utils';
2
+ export default class Bus {
3
+ _paused = false;
4
+ _messageListeners = {};
5
+ _queue = [];
6
+ _send;
7
+ _timeoutId = null;
8
+ constructor(send) {
9
+ this._send = send;
10
+ }
11
+ post(message) {
12
+ return new Promise((resolve) => {
13
+ if (message.type !== 'set' && message.id) {
14
+ this._messageListeners[message.id] = resolve;
15
+ }
16
+ if (!this._paused) {
17
+ this._queue.push(message);
18
+ this.startBatching();
19
+ }
20
+ else {
21
+ this._queue.push(message);
22
+ }
23
+ });
24
+ }
25
+ handle(message) {
26
+ if (!message.id)
27
+ return;
28
+ const handler = this._messageListeners[message.id];
29
+ delete this._messageListeners[message.id];
30
+ if (handler) {
31
+ handler(message);
32
+ }
33
+ else {
34
+ warn(`Received unexpected message: ${message}`);
35
+ }
36
+ }
37
+ pause() {
38
+ this._paused = true;
39
+ }
40
+ resume() {
41
+ this._paused = false;
42
+ this._send(this._queue);
43
+ this._queue = [];
44
+ }
45
+ startBatching() {
46
+ if (this._timeoutId)
47
+ return;
48
+ this._timeoutId = setTimeout(() => {
49
+ this._send(this._queue);
50
+ this._queue = [];
51
+ this._timeoutId = null;
52
+ }, 16);
53
+ }
54
+ clearBatchingTimeout() {
55
+ if (this._timeoutId) {
56
+ clearTimeout(this._timeoutId);
57
+ this._timeoutId = null;
58
+ }
59
+ }
60
+ }
@@ -0,0 +1,15 @@
1
+ import { registerWebviewMethods } from './utils';
2
+ const METHODS = ['addColorStop'];
3
+ export default class CanvasGradient {
4
+ canvas;
5
+ constructor(canvas, noOnConstruction = false) {
6
+ this.canvas = canvas;
7
+ registerWebviewMethods(this, METHODS);
8
+ if (this.onConstruction && !noOnConstruction) {
9
+ this.onConstruction();
10
+ }
11
+ }
12
+ postMessage(message) {
13
+ return this.canvas.postMessage(message);
14
+ }
15
+ }
@@ -0,0 +1,84 @@
1
+ import { registerWebviewProperties, registerWebviewMethods, registerWebviewTarget } from './utils';
2
+ const PROPERTIES = {
3
+ direction: 'inherit',
4
+ fillStyle: '#000',
5
+ filter: 'none',
6
+ font: '10px sans-serif',
7
+ fontKerning: 'auto',
8
+ fontStretch: 'auto',
9
+ fontVariantCaps: 'normal',
10
+ globalAlpha: 1.0,
11
+ globalCompositeOperation: 'source-over',
12
+ imageSmoothingEnabled: 'true',
13
+ imageSmoothingQuality: 'low',
14
+ letterSpacing: '0px',
15
+ lineCap: 'butt',
16
+ lineDashOffset: 0.0,
17
+ lineJoin: 'miter',
18
+ lineWidth: 1.0,
19
+ miterLimit: 10.0,
20
+ shadowBlur: 0,
21
+ shadowColor: 'rgba(0,0,0,0)',
22
+ shadowOffsetX: 0,
23
+ shadowOffsetY: 0,
24
+ strokeStyle: '#000',
25
+ textAlign: 'start',
26
+ textBaseline: 'alphabetic',
27
+ textRendering: 'auto',
28
+ wordSpacing: '0px'
29
+ };
30
+ const METHODS = [
31
+ 'arc',
32
+ 'arcTo',
33
+ 'beginPath',
34
+ 'bezierCurveTo',
35
+ 'clearRect',
36
+ 'clip',
37
+ 'closePath',
38
+ 'createConicGradient',
39
+ 'createImageData',
40
+ 'createLinearGradient',
41
+ 'createPattern',
42
+ 'createRadialGradient',
43
+ 'drawFocusIfNeeded',
44
+ 'drawImage',
45
+ 'ellipse',
46
+ 'fill',
47
+ 'fillRect',
48
+ 'fillText',
49
+ 'getImageData',
50
+ 'getLineDash',
51
+ 'getTransform',
52
+ 'lineTo',
53
+ 'measureText',
54
+ 'moveTo',
55
+ 'putImageData',
56
+ 'quadraticCurveTo',
57
+ 'rect',
58
+ 'reset',
59
+ 'resetTransform',
60
+ 'restore',
61
+ 'rotate',
62
+ 'roundRect',
63
+ 'save',
64
+ 'scale',
65
+ 'setLineDash',
66
+ 'setTransform',
67
+ 'stroke',
68
+ 'strokeRect',
69
+ 'strokeText',
70
+ 'transform',
71
+ 'translate'
72
+ ];
73
+ export default class CanvasRenderingContext2D {
74
+ canvas;
75
+ constructor(canvas) {
76
+ this.canvas = canvas;
77
+ registerWebviewTarget(this, 'context2D');
78
+ registerWebviewProperties(this, PROPERTIES);
79
+ registerWebviewMethods(this, METHODS);
80
+ }
81
+ postMessage(message) {
82
+ return this.canvas.postMessage(message);
83
+ }
84
+ }
@@ -0,0 +1,87 @@
1
+ import { WEBVIEW_TARGET, registerWebviewProperties } from './utils';
2
+ const PROPERTIES = {
3
+ crossOrigin: undefined,
4
+ height: undefined,
5
+ src: undefined,
6
+ width: undefined
7
+ };
8
+ export class Image {
9
+ [WEBVIEW_TARGET];
10
+ canvas;
11
+ width;
12
+ height;
13
+ _loadListener;
14
+ _errorListener;
15
+ _onload;
16
+ _onerror;
17
+ constructor(canvas, width, height, noOnConstruction = false) {
18
+ this.canvas = canvas;
19
+ registerWebviewProperties(this, PROPERTIES);
20
+ if (width) {
21
+ this.width = width;
22
+ }
23
+ if (height) {
24
+ this.height = height;
25
+ }
26
+ if (this.onConstruction && !noOnConstruction) {
27
+ this.onConstruction();
28
+ this.postMessage({
29
+ type: 'listen',
30
+ payload: {
31
+ types: ['error', 'load'],
32
+ target: this[WEBVIEW_TARGET]
33
+ }
34
+ });
35
+ }
36
+ }
37
+ postMessage(message) {
38
+ return this.canvas.postMessage(message);
39
+ }
40
+ addEventListener(type, callbackFn) {
41
+ return this.canvas.addMessageListener((message) => {
42
+ const target = message?.payload?.target || {};
43
+ if (message &&
44
+ message.type === 'event' &&
45
+ target[WEBVIEW_TARGET] === this[WEBVIEW_TARGET] &&
46
+ message.payload.type === type) {
47
+ for (const key in target) {
48
+ const value = target[key];
49
+ if (key in this && this[key] !== value) {
50
+ this[key] = value;
51
+ }
52
+ }
53
+ callbackFn({
54
+ ...message.payload,
55
+ target: this
56
+ });
57
+ }
58
+ });
59
+ }
60
+ set onload(callback) {
61
+ this._onload = callback;
62
+ if (this._loadListener) {
63
+ this.canvas.removeMessageListener(this._loadListener);
64
+ }
65
+ if (callback) {
66
+ this._loadListener = this.addEventListener('load', callback);
67
+ }
68
+ }
69
+ get onload() {
70
+ return this._onload;
71
+ }
72
+ set onerror(callback) {
73
+ this._onerror = callback;
74
+ if (this._errorListener) {
75
+ this.canvas.removeMessageListener(this._errorListener);
76
+ }
77
+ if (callback) {
78
+ this._errorListener = this.addEventListener('error', callback);
79
+ }
80
+ }
81
+ get onerror() {
82
+ return this._onerror;
83
+ }
84
+ }
85
+ export function createImage(canvas, width, height) {
86
+ return new Image(canvas, width, height);
87
+ }
@@ -0,0 +1,15 @@
1
+ export default class ImageData {
2
+ canvas;
3
+ constructor(canvas, dataArray, width, height, noOnConstruction) {
4
+ this.canvas = canvas;
5
+ if (this.onConstruction && !noOnConstruction) {
6
+ this.onConstruction(dataArray, width, height);
7
+ }
8
+ }
9
+ postMessage = (message) => {
10
+ return this.canvas.postMessage(message);
11
+ };
12
+ }
13
+ export function createImageData(canvas, dataArray, width, height) {
14
+ return new ImageData(canvas, dataArray, width, height);
15
+ }
@@ -0,0 +1,28 @@
1
+ import { Image } from './Image';
2
+ import CanvasGradient from './CanvasGradient';
3
+ import ImageData from './ImageData';
4
+ export var ConstructorType;
5
+ (function (ConstructorType) {
6
+ ConstructorType["Image"] = "Image";
7
+ ConstructorType["CanvasGradient"] = "CanvasGradient";
8
+ ConstructorType["ImageData"] = "ImageData";
9
+ })(ConstructorType || (ConstructorType = {}));
10
+ const constructors = [
11
+ { type: ConstructorType.Image, instance: Image },
12
+ { type: ConstructorType.CanvasGradient, instance: CanvasGradient },
13
+ { type: ConstructorType.ImageData, instance: ImageData }
14
+ ];
15
+ export function useConstructorsRegistry() {
16
+ const register = (registerWebviewConstructor) => {
17
+ constructors.forEach(({ type, instance }) => {
18
+ registerWebviewConstructor(instance, type);
19
+ });
20
+ };
21
+ const getConstructor = (type) => {
22
+ return constructors.find(c => c.type === type)?.instance;
23
+ };
24
+ return {
25
+ register,
26
+ getConstructor
27
+ };
28
+ }