@rsmax/runtime 1.0.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.
Files changed (140) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/cjs/AppContainer.d.ts +22 -0
  3. package/cjs/AppContainer.js +40 -0
  4. package/cjs/Container.d.ts +39 -0
  5. package/cjs/Container.js +120 -0
  6. package/cjs/ReactPortal.d.ts +2 -0
  7. package/cjs/ReactPortal.js +15 -0
  8. package/cjs/SyntheticEvent/constants.d.ts +2 -0
  9. package/cjs/SyntheticEvent/constants.js +13 -0
  10. package/cjs/SyntheticEvent/createCallbackProxy.d.ts +2 -0
  11. package/cjs/SyntheticEvent/createCallbackProxy.js +59 -0
  12. package/cjs/SyntheticEvent/stopPropagation.d.ts +13 -0
  13. package/cjs/SyntheticEvent/stopPropagation.js +33 -0
  14. package/cjs/VNode.d.ts +45 -0
  15. package/cjs/VNode.js +276 -0
  16. package/cjs/constants.d.ts +3 -0
  17. package/cjs/constants.js +6 -0
  18. package/cjs/createAppConfig.d.ts +2 -0
  19. package/cjs/createAppConfig.js +124 -0
  20. package/cjs/createComponentConfig.d.ts +2 -0
  21. package/cjs/createComponentConfig.js +74 -0
  22. package/cjs/createComponentConfig.wechat.d.ts +2 -0
  23. package/cjs/createComponentConfig.wechat.js +89 -0
  24. package/cjs/createHostComponent.d.ts +2 -0
  25. package/cjs/createHostComponent.js +20 -0
  26. package/cjs/createNativeComponent.d.ts +2 -0
  27. package/cjs/createNativeComponent.js +23 -0
  28. package/cjs/createPageConfig.d.ts +3 -0
  29. package/cjs/createPageConfig.js +191 -0
  30. package/cjs/hooks/index.d.ts +3 -0
  31. package/cjs/hooks/index.js +15 -0
  32. package/cjs/hooks/useNativeEffect.d.ts +3 -0
  33. package/cjs/hooks/useNativeEffect.js +13 -0
  34. package/cjs/hooks/useQuery.d.ts +3 -0
  35. package/cjs/hooks/useQuery.js +9 -0
  36. package/cjs/hostConfig/diffProperties.d.ts +1 -0
  37. package/cjs/hostConfig/diffProperties.js +100 -0
  38. package/cjs/hostConfig/index.d.ts +42 -0
  39. package/cjs/hostConfig/index.js +159 -0
  40. package/cjs/index.d.ts +14 -0
  41. package/cjs/index.js +43 -0
  42. package/cjs/instanceId.d.ts +2 -0
  43. package/cjs/instanceId.js +14 -0
  44. package/cjs/nativeEffect.d.ts +10 -0
  45. package/cjs/nativeEffect.js +25 -0
  46. package/cjs/polyfills/Function.d.ts +0 -0
  47. package/cjs/polyfills/Function.js +29 -0
  48. package/cjs/propsAlias.d.ts +6 -0
  49. package/cjs/propsAlias.js +51 -0
  50. package/cjs/render.d.ts +6 -0
  51. package/cjs/render.js +35 -0
  52. package/cjs/stopPullDownRefresh/index.ali.d.ts +2 -0
  53. package/cjs/stopPullDownRefresh/index.ali.js +3 -0
  54. package/cjs/stopPullDownRefresh/index.d.ts +1 -0
  55. package/cjs/stopPullDownRefresh/index.js +6 -0
  56. package/cjs/stopPullDownRefresh/index.toutiao.d.ts +2 -0
  57. package/cjs/stopPullDownRefresh/index.toutiao.js +3 -0
  58. package/cjs/stopPullDownRefresh/index.wechat.d.ts +2 -0
  59. package/cjs/stopPullDownRefresh/index.wechat.js +3 -0
  60. package/cjs/utils/capitalize.d.ts +1 -0
  61. package/cjs/utils/capitalize.js +6 -0
  62. package/cjs/utils/isClassComponent.d.ts +2 -0
  63. package/cjs/utils/isClassComponent.js +6 -0
  64. package/cjs/utils/lowercase.d.ts +1 -0
  65. package/cjs/utils/lowercase.js +6 -0
  66. package/cjs/utils/plainStyle/CSSProperty.d.ts +6 -0
  67. package/cjs/utils/plainStyle/CSSProperty.js +71 -0
  68. package/cjs/utils/plainStyle/index.d.ts +2 -0
  69. package/cjs/utils/plainStyle/index.js +45 -0
  70. package/esm/AppContainer.d.ts +22 -0
  71. package/esm/AppContainer.js +34 -0
  72. package/esm/Container.d.ts +39 -0
  73. package/esm/Container.js +114 -0
  74. package/esm/ReactPortal.d.ts +2 -0
  75. package/esm/ReactPortal.js +11 -0
  76. package/esm/SyntheticEvent/constants.d.ts +2 -0
  77. package/esm/SyntheticEvent/constants.js +10 -0
  78. package/esm/SyntheticEvent/createCallbackProxy.d.ts +2 -0
  79. package/esm/SyntheticEvent/createCallbackProxy.js +32 -0
  80. package/esm/SyntheticEvent/stopPropagation.d.ts +13 -0
  81. package/esm/SyntheticEvent/stopPropagation.js +28 -0
  82. package/esm/VNode.d.ts +45 -0
  83. package/esm/VNode.js +250 -0
  84. package/esm/constants.d.ts +3 -0
  85. package/esm/constants.js +3 -0
  86. package/esm/createAppConfig.d.ts +2 -0
  87. package/esm/createAppConfig.js +95 -0
  88. package/esm/createComponentConfig.d.ts +2 -0
  89. package/esm/createComponentConfig.js +45 -0
  90. package/esm/createComponentConfig.wechat.d.ts +2 -0
  91. package/esm/createComponentConfig.wechat.js +60 -0
  92. package/esm/createHostComponent.d.ts +2 -0
  93. package/esm/createHostComponent.js +14 -0
  94. package/esm/createNativeComponent.d.ts +2 -0
  95. package/esm/createNativeComponent.js +17 -0
  96. package/esm/createPageConfig.d.ts +3 -0
  97. package/esm/createPageConfig.js +183 -0
  98. package/esm/hooks/index.d.ts +3 -0
  99. package/esm/hooks/index.js +3 -0
  100. package/esm/hooks/useNativeEffect.d.ts +3 -0
  101. package/esm/hooks/useNativeEffect.js +7 -0
  102. package/esm/hooks/useQuery.d.ts +3 -0
  103. package/esm/hooks/useQuery.js +6 -0
  104. package/esm/hostConfig/diffProperties.d.ts +1 -0
  105. package/esm/hostConfig/diffProperties.js +97 -0
  106. package/esm/hostConfig/index.d.ts +42 -0
  107. package/esm/hostConfig/index.js +154 -0
  108. package/esm/index.d.ts +14 -0
  109. package/esm/index.js +14 -0
  110. package/esm/instanceId.d.ts +2 -0
  111. package/esm/instanceId.js +9 -0
  112. package/esm/nativeEffect.d.ts +10 -0
  113. package/esm/nativeEffect.js +23 -0
  114. package/esm/polyfills/Function.d.ts +0 -0
  115. package/esm/polyfills/Function.js +29 -0
  116. package/esm/propsAlias.d.ts +6 -0
  117. package/esm/propsAlias.js +42 -0
  118. package/esm/render.d.ts +6 -0
  119. package/esm/render.js +28 -0
  120. package/esm/stopPullDownRefresh/index.ali.d.ts +2 -0
  121. package/esm/stopPullDownRefresh/index.ali.js +1 -0
  122. package/esm/stopPullDownRefresh/index.d.ts +1 -0
  123. package/esm/stopPullDownRefresh/index.js +3 -0
  124. package/esm/stopPullDownRefresh/index.toutiao.d.ts +2 -0
  125. package/esm/stopPullDownRefresh/index.toutiao.js +1 -0
  126. package/esm/stopPullDownRefresh/index.wechat.d.ts +2 -0
  127. package/esm/stopPullDownRefresh/index.wechat.js +1 -0
  128. package/esm/utils/capitalize.d.ts +1 -0
  129. package/esm/utils/capitalize.js +3 -0
  130. package/esm/utils/isClassComponent.d.ts +2 -0
  131. package/esm/utils/isClassComponent.js +3 -0
  132. package/esm/utils/lowercase.d.ts +1 -0
  133. package/esm/utils/lowercase.js +3 -0
  134. package/esm/utils/plainStyle/CSSProperty.d.ts +6 -0
  135. package/esm/utils/plainStyle/CSSProperty.js +68 -0
  136. package/esm/utils/plainStyle/index.d.ts +2 -0
  137. package/esm/utils/plainStyle/index.js +43 -0
  138. package/package.json +56 -0
  139. package/typings/index.d.ts +6 -0
  140. package/vitest.config.js +9 -0
@@ -0,0 +1,6 @@
1
+ import * as React from 'react';
2
+ import ReactReconciler from 'react-reconciler';
3
+ import Container from './Container';
4
+ import AppContainer from './AppContainer';
5
+ export declare const ReactReconcilerInst: ReactReconciler.Reconciler<unknown, unknown, unknown, unknown, unknown>;
6
+ export default function render(rootElement: React.ReactElement | null, container: Container | AppContainer): any;
package/esm/render.js ADDED
@@ -0,0 +1,28 @@
1
+ import ReactReconciler from 'react-reconciler';
2
+ import hostConfig from './hostConfig';
3
+ export const ReactReconcilerInst = ReactReconciler(hostConfig);
4
+ if (process.env.NODE_ENV === 'development') {
5
+ ReactReconcilerInst.injectIntoDevTools({
6
+ bundleType: 1,
7
+ version: '18.3.0',
8
+ rendererPackageName: 'remax',
9
+ });
10
+ }
11
+ function getPublicRootInstance(container) {
12
+ const containerFiber = container.current;
13
+ if (!containerFiber.child) {
14
+ return null;
15
+ }
16
+ return containerFiber.child.stateNode;
17
+ }
18
+ export default function render(rootElement, container) {
19
+ // Create a root Container if it doesnt exist
20
+ if (!container._rootContainer) {
21
+ // eslint-disable-next-line @typescript-eslint/no-empty-function
22
+ container._rootContainer = ReactReconcilerInst.createContainer(container, 0, null, false, null, '', () => { }, null);
23
+ }
24
+ ReactReconcilerInst.updateContainer(rootElement, container._rootContainer, null, () => {
25
+ // ignore
26
+ });
27
+ return getPublicRootInstance(container._rootContainer);
28
+ }
@@ -0,0 +1,2 @@
1
+ declare const _default: any;
2
+ export default _default;
@@ -0,0 +1 @@
1
+ export default my.stopPullDownRefresh;
@@ -0,0 +1 @@
1
+ export default function stopPullDownRefresh(): void;
@@ -0,0 +1,3 @@
1
+ export default function stopPullDownRefresh() {
2
+ // do nothing
3
+ }
@@ -0,0 +1,2 @@
1
+ declare const _default: any;
2
+ export default _default;
@@ -0,0 +1 @@
1
+ export default tt.stopPullDownRefresh;
@@ -0,0 +1,2 @@
1
+ declare const _default: any;
2
+ export default _default;
@@ -0,0 +1 @@
1
+ export default wx.stopPullDownRefresh;
@@ -0,0 +1 @@
1
+ export default function capitalize(str: string): string;
@@ -0,0 +1,3 @@
1
+ export default function capitalize(str) {
2
+ return str.charAt(0).toUpperCase() + str.slice(1);
3
+ }
@@ -0,0 +1,2 @@
1
+ import { ComponentClass } from 'react';
2
+ export default function isClassComponent(Component: any): Component is ComponentClass;
@@ -0,0 +1,3 @@
1
+ export default function isClassComponent(Component) {
2
+ return Component.prototype && typeof Component.prototype.render === 'function';
3
+ }
@@ -0,0 +1 @@
1
+ export default function lowercase(str: string): string;
@@ -0,0 +1,3 @@
1
+ export default function lowercase(str) {
2
+ return str.charAt(0).toLowerCase() + str.slice(1);
3
+ }
@@ -0,0 +1,6 @@
1
+ /**
2
+ * CSS properties which accept numbers but are not in units of "px".
3
+ */
4
+ export declare const isUnitlessNumber: {
5
+ [key: string]: boolean;
6
+ };
@@ -0,0 +1,68 @@
1
+ // https://github.com/facebook/react/blob/master/packages/react-dom/src/shared/CSSProperty.js
2
+ /**
3
+ * CSS properties which accept numbers but are not in units of "px".
4
+ */
5
+ export const isUnitlessNumber = {
6
+ animationIterationCount: true,
7
+ borderImageOutset: true,
8
+ borderImageSlice: true,
9
+ borderImageWidth: true,
10
+ boxFlex: true,
11
+ boxFlexGroup: true,
12
+ boxOrdinalGroup: true,
13
+ columnCount: true,
14
+ columns: true,
15
+ flex: true,
16
+ flexGrow: true,
17
+ flexPositive: true,
18
+ flexShrink: true,
19
+ flexNegative: true,
20
+ flexOrder: true,
21
+ gridArea: true,
22
+ gridRow: true,
23
+ gridRowEnd: true,
24
+ gridRowSpan: true,
25
+ gridRowStart: true,
26
+ gridColumn: true,
27
+ gridColumnEnd: true,
28
+ gridColumnSpan: true,
29
+ gridColumnStart: true,
30
+ fontWeight: true,
31
+ lineClamp: true,
32
+ lineHeight: true,
33
+ opacity: true,
34
+ order: true,
35
+ orphans: true,
36
+ tabSize: true,
37
+ widows: true,
38
+ zIndex: true,
39
+ zoom: true,
40
+ // SVG-related properties
41
+ fillOpacity: true,
42
+ floodOpacity: true,
43
+ stopOpacity: true,
44
+ strokeDasharray: true,
45
+ strokeDashoffset: true,
46
+ strokeMiterlimit: true,
47
+ strokeOpacity: true,
48
+ strokeWidth: true,
49
+ };
50
+ /**
51
+ * @param {string} prefix vendor-specific prefix, eg: Webkit
52
+ * @param {string} key style name, eg: transitionDuration
53
+ * @return {string} style name prefixed with `prefix`, properly camelCased, eg:
54
+ * WebkitTransitionDuration
55
+ */
56
+ function prefixKey(prefix, key) {
57
+ return prefix + key.charAt(0).toUpperCase() + key.substring(1);
58
+ }
59
+ /**
60
+ * Support style names that may come passed in prefixed by adding permutations
61
+ * of vendor prefixes.
62
+ */
63
+ const prefixes = ['Webkit', 'ms', 'Moz', 'O'];
64
+ for (const prop in isUnitlessNumber) {
65
+ prefixes.forEach(function (prefix) {
66
+ isUnitlessNumber[prefixKey(prefix, prop)] = isUnitlessNumber[prop];
67
+ });
68
+ }
@@ -0,0 +1,2 @@
1
+ declare const plainStyle: (style: Record<string, string | number>) => string;
2
+ export default plainStyle;
@@ -0,0 +1,43 @@
1
+ import { isUnitlessNumber } from './CSSProperty';
2
+ import { find, RuntimeOptions } from '@rsmax/framework-shared';
3
+ const vendorPrefixes = ['webkit', 'moz', 'ms', 'o'];
4
+ const transformReactStyleKey = (key) => {
5
+ // css3 var
6
+ if (key === null || key === void 0 ? void 0 : key.startsWith('--')) {
7
+ return key;
8
+ }
9
+ let styleValue = key.replace(/\.?([A-Z]+)/g, function (_x, y) {
10
+ return '-' + y.toLowerCase();
11
+ });
12
+ // vendor prefix
13
+ if (styleValue === null || styleValue === void 0 ? void 0 : styleValue.startsWith('-')) {
14
+ const firstWord = styleValue.split('-').filter(s => s)[0];
15
+ styleValue = styleValue.replace(/^-/, '');
16
+ if (find(vendorPrefixes, prefix => prefix === firstWord)) {
17
+ styleValue = '-' + styleValue;
18
+ }
19
+ }
20
+ return styleValue;
21
+ };
22
+ const transformPx = (value) => {
23
+ if (typeof value !== 'string') {
24
+ return value;
25
+ }
26
+ return value.replace(/\b(\d+(\.\d+)?)px\b/g, function (match, x) {
27
+ const targetUnit = 'rpx';
28
+ const size = Number(x);
29
+ return size % 1 === 0 ? size + targetUnit : size.toFixed(2) + targetUnit;
30
+ });
31
+ };
32
+ const plainStyle = (style) => {
33
+ return Object.keys(style)
34
+ .reduce((acc, key) => {
35
+ let value = style[key];
36
+ if (!Number.isNaN(Number(value)) && !isUnitlessNumber[key] && !(key === null || key === void 0 ? void 0 : key.startsWith('--'))) {
37
+ value = value + 'rpx';
38
+ }
39
+ return [...acc, `${transformReactStyleKey(key)}:${RuntimeOptions.get('pxToRpx') ? transformPx(value) : value};`];
40
+ }, [])
41
+ .join('');
42
+ };
43
+ export default plainStyle;
package/package.json ADDED
@@ -0,0 +1,56 @@
1
+ {
2
+ "name": "@rsmax/runtime",
3
+ "version": "1.0.1",
4
+ "description": "Rsmax 是一个全新的基于 React 的小程序开发框架",
5
+ "main": "./cjs/index.js",
6
+ "esnext": "./esm/index.js",
7
+ "module": "./esm/index.js",
8
+ "typings": "./esm/index.d.ts",
9
+ "keywords": [
10
+ "react",
11
+ "miniapp",
12
+ "mini-program",
13
+ "wechat"
14
+ ],
15
+ "license": "MIT",
16
+ "bugs": {
17
+ "url": "https://github.com/remaxjs/remax/issues"
18
+ },
19
+ "repository": {
20
+ "type": "git",
21
+ "url": "git+https://github.com/remaxjs/remax.git"
22
+ },
23
+ "homepage": "https://remaxjs.org",
24
+ "scripts": {
25
+ "clean": "rimraf esm cjs tsconfig.tsbuildinfo",
26
+ "prebuild": "npm run clean",
27
+ "build": "tsc",
28
+ "build:cjs": "tsc --module CommonJS --outDir cjs",
29
+ "test": "vitest run"
30
+ },
31
+ "dependencies": {
32
+ "@rsmax/framework-shared": "workspace:*",
33
+ "@rsmax/shared": "workspace:*",
34
+ "@rsmax/web": "workspace:*",
35
+ "qs": "^6.9.3",
36
+ "react-is": "^18.3.0",
37
+ "react-reconciler": "0.29.0",
38
+ "scheduler": "0.19.1"
39
+ },
40
+ "devDependencies": {
41
+ "@rsmax/types": "workspace:*",
42
+ "@types/lodash.merge": "^4.6.6",
43
+ "@types/node": "^18",
44
+ "@types/qs": "^6.9.3",
45
+ "@types/react": "^18.3.0",
46
+ "@types/react-is": "^18.3.0",
47
+ "@types/react-reconciler": "0.28.8",
48
+ "@types/react-test-renderer": "^18.3.0",
49
+ "object-path-immutable": "^4.0.2",
50
+ "react-test-renderer": "^18.3.0"
51
+ },
52
+ "publishConfig": {
53
+ "access": "public"
54
+ },
55
+ "gitHead": "d2ff644810449152d124a9da76218bcd9fdfff46"
56
+ }
@@ -0,0 +1,6 @@
1
+ declare module 'scheduler';
2
+ declare const tt: any;
3
+ declare const my: any;
4
+ declare const getCurrentPages: any;
5
+ declare const getApp: any;
6
+ declare module 'react-devtools-core';
@@ -0,0 +1,9 @@
1
+ import { defineConfig } from 'vitest/config';
2
+
3
+ export default defineConfig({
4
+ test: {
5
+ globals: true,
6
+ // todo 这里的 cjs 包存在问题
7
+ exclude: ['cjs/**/*', 'esm/**/*', 'node_modules/**/*'],
8
+ },
9
+ });