android: Update JSC and compat new api

This commit is contained in:
pengfei.zhou 2022-03-09 17:35:13 +08:00 committed by osborn
parent 774d3160a9
commit 8aebbc7a36
19 changed files with 1906 additions and 3122 deletions

View File

@ -31,7 +31,7 @@ dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar']) implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.3.1' implementation 'androidx.appcompat:appcompat:1.3.1'
api 'com.github.penfeizhou:jsc4a:0.3.5' api 'com.github.penfeizhou:jsc4a:0.3.6'
//api "pub.doric:jse:${rootProject.ext.Version}" //api "pub.doric:jse:${rootProject.ext.Version}"
implementation 'com.squareup.okhttp3:okhttp:3.12.1' implementation 'com.squareup.okhttp3:okhttp:3.12.1'
implementation('com.github.penfeizhou.android.animation:glide-plugin:2.17.0') { implementation('com.github.penfeizhou.android.animation:glide-plugin:2.17.0') {

View File

@ -15,6 +15,8 @@
*/ */
package pub.doric.engine; package pub.doric.engine;
import android.util.Base64;
import com.github.pengfeizhou.jscore.ArchiveException; import com.github.pengfeizhou.jscore.ArchiveException;
import com.github.pengfeizhou.jscore.JSArray; import com.github.pengfeizhou.jscore.JSArray;
import com.github.pengfeizhou.jscore.JSArrayBuffer; import com.github.pengfeizhou.jscore.JSArrayBuffer;
@ -98,6 +100,11 @@ public class DoricJSDecoder extends JSDecoder {
return new JSBoolean((Boolean) this.value); return new JSBoolean((Boolean) this.value);
} }
if (isString()) { if (isString()) {
if (((String) this.value).startsWith("__buffer_")) {
String base64String = ((String) this.value).substring("__buffer_".length());
byte[] data = Base64.decode(base64String, 0);
return new DoricJSArrayBuffer(data);
}
return new JSString((String) this.value); return new JSString((String) this.value);
} }
if (isNumber()) { if (isNumber()) {
@ -129,8 +136,22 @@ public class DoricJSDecoder extends JSDecoder {
return jsArray; return jsArray;
} }
if (this.value instanceof byte[]) { if (this.value instanceof byte[]) {
return new JSArrayBuffer((byte[]) this.value); return new DoricJSArrayBuffer((byte[]) this.value);
} }
return JS_NULL; return JS_NULL;
} }
private static class DoricJSArrayBuffer extends JSArrayBuffer {
private final byte[] data;
public DoricJSArrayBuffer(byte[] data) {
super(0, data.length);
this.data = data;
}
@Override
public byte[] value() {
return this.data;
}
}
} }

View File

@ -4,20 +4,21 @@ import com.github.pengfeizhou.jscore.JavaValue;
import java.lang.ref.SoftReference; import java.lang.ref.SoftReference;
import java.lang.ref.WeakReference; import java.lang.ref.WeakReference;
import java.nio.ByteBuffer;
import pub.doric.DoricContext; import pub.doric.DoricContext;
public class RetainedJavaValue extends JavaValue { public class RetainedJavaValue extends JavaValue {
private final WeakReference<DoricContext> contextRef; private final WeakReference<DoricContext> contextRef;
public RetainedJavaValue(DoricContext doricContext, byte[] data) { public RetainedJavaValue(DoricContext doricContext, ByteBuffer data) {
super(data); super(data, null);
contextRef = new WeakReference<>(doricContext); contextRef = new WeakReference<>(doricContext);
final SoftReference<RetainedJavaValue> softRef = new SoftReference<>(this); final SoftReference<RetainedJavaValue> softRef = new SoftReference<>(this);
doricContext.retainJavaValue(softRef); doricContext.retainJavaValue(softRef);
this.memoryReleaser = new MemoryReleaser() { this.memoryReleaser = new MemoryReleaser() {
@Override @Override
public void deallocate(byte[] data) { public void deallocate(ByteBuffer data) {
if (contextRef.get() != null) { if (contextRef.get() != null) {
contextRef.get().releaseJavaValue(softRef); contextRef.get().releaseJavaValue(softRef);
} }

View File

@ -32,6 +32,7 @@ import pub.doric.extension.bridge.DoricPlugin;
import pub.doric.extension.bridge.DoricPromise; import pub.doric.extension.bridge.DoricPromise;
import pub.doric.resource.DoricResource; import pub.doric.resource.DoricResource;
import pub.doric.utils.DoricLog; import pub.doric.utils.DoricLog;
import pub.doric.utils.ThreadMode;
/** /**
* @Description: This is for loading resource into js as ArrayBuffer * @Description: This is for loading resource into js as ArrayBuffer
@ -45,7 +46,7 @@ public class ImageDecoderPlugin extends DoricJavaPlugin {
super(doricContext); super(doricContext);
} }
@DoricMethod @DoricMethod(thread = ThreadMode.UI)
public void getImageInfo(final JSObject resource, final DoricPromise promise) { public void getImageInfo(final JSObject resource, final DoricPromise promise) {
DoricResource doricResource = getDoricContext().getDriver().getRegistry().getResourceManager().load( DoricResource doricResource = getDoricContext().getDriver().getRegistry().getResourceManager().load(
getDoricContext(), getDoricContext(),
@ -82,7 +83,8 @@ public class ImageDecoderPlugin extends DoricJavaPlugin {
} }
} }
@DoricMethod
@DoricMethod(thread = ThreadMode.UI)
public void decodeToPixels(final JSObject resource, final DoricPromise promise) { public void decodeToPixels(final JSObject resource, final DoricPromise promise) {
DoricResource doricResource = getDoricContext().getDriver().getRegistry().getResourceManager().load( DoricResource doricResource = getDoricContext().getDriver().getRegistry().getResourceManager().load(
getDoricContext(), getDoricContext(),
@ -90,13 +92,13 @@ public class ImageDecoderPlugin extends DoricJavaPlugin {
if (doricResource != null) { if (doricResource != null) {
doricResource.fetch().setCallback(new AsyncResult.Callback<byte[]>() { doricResource.fetch().setCallback(new AsyncResult.Callback<byte[]>() {
@Override @Override
public void onResult(byte[] rawData) { public void onResult(final byte[] rawData) {
BitmapFactory.Options options = new BitmapFactory.Options(); BitmapFactory.Options options = new BitmapFactory.Options();
options.inPreferredConfig = Bitmap.Config.ARGB_8888; options.inPreferredConfig = Bitmap.Config.ARGB_8888;
Bitmap bitmap = BitmapFactory.decodeByteArray(rawData, 0, rawData.length); Bitmap bitmap = BitmapFactory.decodeByteArray(rawData, 0, rawData.length, options);
ByteBuffer buffer = ByteBuffer.allocate(bitmap.getByteCount()); ByteBuffer buffer = ByteBuffer.allocateDirect(bitmap.getByteCount());
bitmap.copyPixelsToBuffer(buffer); bitmap.copyPixelsToBuffer(buffer);
RetainedJavaValue retainedJavaValue = new RetainedJavaValue(getDoricContext(), buffer.array()); final RetainedJavaValue retainedJavaValue = new RetainedJavaValue(getDoricContext(), buffer);
promise.resolve(retainedJavaValue); promise.resolve(retainedJavaValue);
} }

View File

@ -3,6 +3,10 @@ package com.github.pengfeizhou.jscore;
public class JSArrayBuffer extends JSValue { public class JSArrayBuffer extends JSValue {
private final byte[] mVal; private final byte[] mVal;
public JSArrayBuffer(long ptr, int length) {
this.mVal = new byte[0];
}
public JSArrayBuffer(byte[] val) { public JSArrayBuffer(byte[] val) {
this.mVal = val; this.mVal = val;
} }

View File

@ -18,6 +18,8 @@ package com.github.pengfeizhou.jscore;
import org.json.JSONArray; import org.json.JSONArray;
import org.json.JSONObject; import org.json.JSONObject;
import java.nio.ByteBuffer;
public class JavaValue { public class JavaValue {
protected static final int TYPE_NULL = 0; protected static final int TYPE_NULL = 0;
protected static final int TYPE_NUMBER = 1; protected static final int TYPE_NUMBER = 1;
@ -31,7 +33,7 @@ public class JavaValue {
protected String[] functionNames = null; protected String[] functionNames = null;
protected int type; protected int type;
protected String value = ""; protected String value = "";
protected byte[] data = null; protected ByteBuffer data = null;
protected MemoryReleaser memoryReleaser = null; protected MemoryReleaser memoryReleaser = null;
public JavaValue() { public JavaValue() {
@ -79,17 +81,24 @@ public class JavaValue {
this.value = jsonArray.toString(); this.value = jsonArray.toString();
} }
public JavaValue(byte[] data) { public JavaValue(byte[] data, MemoryReleaser memoryReleaser) {
this.type = TYPE_ARRAYBUFFER; this.type = TYPE_ARRAYBUFFER;
this.data = data; this.data = ByteBuffer.allocateDirect(data.length);
this.data.put(data);
this.memoryReleaser = memoryReleaser;
} }
public JavaValue(byte[] data, MemoryReleaser memoryReleaser) { public JavaValue(ByteBuffer data, MemoryReleaser memoryReleaser) {
this.type = TYPE_ARRAYBUFFER; this.type = TYPE_ARRAYBUFFER;
this.data = data; this.data = data;
this.memoryReleaser = memoryReleaser; this.memoryReleaser = memoryReleaser;
} }
public JavaValue(byte[] data) {
this(data, null);
}
public int getType() { public int getType() {
return type; return type;
} }
@ -99,14 +108,15 @@ public class JavaValue {
} }
public byte[] getByteData() { public byte[] getByteData() {
return data; return data.array();
} }
public interface MemoryReleaser { public interface MemoryReleaser {
/** /**
* Called when JS deallocated the arraybuffer * Called when JS deallocated the arraybuffer
*/ */
void deallocate(byte[] data); void deallocate(ByteBuffer data);
} }
/** /**

View File

@ -68,7 +68,7 @@ var Mutable = /** @class */ (function () {
*/ */
var __uniqueId__ = 0; var __uniqueId__ = 0;
function uniqueId(prefix) { function uniqueId(prefix) {
return "__".concat(prefix, "_").concat(__uniqueId__++, "__"); return "__" + prefix + "_" + __uniqueId__++ + "__";
} }
function toString(message) { function toString(message) {
@ -177,11 +177,11 @@ var __values$5 = (undefined && undefined.__values) || function(o) {
function Property(target, propKey) { function Property(target, propKey) {
Object.defineProperty(target, propKey, { Object.defineProperty(target, propKey, {
get: function () { get: function () {
return Reflect.get(this, "__prop__".concat(propKey), this); return Reflect.get(this, "__prop__" + propKey, this);
}, },
set: function (v) { set: function (v) {
var oldV = Reflect.get(this, "__prop__".concat(propKey), this); var oldV = Reflect.get(this, "__prop__" + propKey, this);
Reflect.set(this, "__prop__".concat(propKey), v, this); Reflect.set(this, "__prop__" + propKey, v, this);
if (oldV !== v) { if (oldV !== v) {
Reflect.apply(this.onPropertyChanged, this, [propKey, oldV, v]); Reflect.apply(this.onPropertyChanged, this, [propKey, oldV, v]);
} }
@ -191,11 +191,11 @@ function Property(target, propKey) {
function InconsistProperty(target, propKey) { function InconsistProperty(target, propKey) {
Object.defineProperty(target, propKey, { Object.defineProperty(target, propKey, {
get: function () { get: function () {
return Reflect.get(this, "__prop__".concat(propKey), this); return Reflect.get(this, "__prop__" + propKey, this);
}, },
set: function (v) { set: function (v) {
var oldV = Reflect.get(this, "__prop__".concat(propKey), this); var oldV = Reflect.get(this, "__prop__" + propKey, this);
Reflect.set(this, "__prop__".concat(propKey), v, this); Reflect.set(this, "__prop__" + propKey, v, this);
Reflect.apply(this.onPropertyChanged, this, [propKey, oldV, v]); Reflect.apply(this.onPropertyChanged, this, [propKey, oldV, v]);
}, },
}); });
@ -373,7 +373,7 @@ var View = /** @class */ (function () {
return Reflect.apply(f, this, argumentsList); return Reflect.apply(f, this, argumentsList);
} }
else { else {
loge("Cannot find callback:".concat(id, " for ").concat(JSON.stringify(this.toModel()))); loge("Cannot find callback:" + id + " for " + JSON.stringify(this.toModel()));
} }
}; };
View.prototype.toModel = function () { View.prototype.toModel = function () {
@ -714,7 +714,7 @@ var Group = /** @class */ (function (_super) {
this.addChild(e); this.addChild(e);
} }
else { else {
loge("Not allowed to add ".concat(typeof e)); loge("Not allowed to add " + typeof e);
} }
}; };
Object.defineProperty(Group.prototype, "innerElement", { Object.defineProperty(Group.prototype, "innerElement", {
@ -1225,7 +1225,7 @@ var Panel = /** @class */ (function () {
var v = this.retrospectView(viewIds); var v = this.retrospectView(viewIds);
if (v === undefined) { if (v === undefined) {
loge("Cannot find view for ".concat(viewIds)); loge("Cannot find view for " + viewIds);
} }
else { else {
var argumentsList = [callbackId]; var argumentsList = [callbackId];
@ -1427,7 +1427,7 @@ var Color = /** @class */ (function () {
} }
Color.parse = function (str) { Color.parse = function (str) {
if (!str.startsWith("#")) { if (!str.startsWith("#")) {
throw new Error("Parse color error with ".concat(str)); throw new Error("Parse color error with " + str);
} }
var val = parseInt(str.substr(1), 16); var val = parseInt(str.substr(1), 16);
if (str.length === 7) { if (str.length === 7) {
@ -1437,7 +1437,7 @@ var Color = /** @class */ (function () {
return new Color(val); return new Color(val);
} }
else { else {
throw new Error("Parse color error with ".concat(str)); throw new Error("Parse color error with " + str);
} }
}; };
Color.safeParse = function (str, defVal) { Color.safeParse = function (str, defVal) {
@ -2240,10 +2240,24 @@ var MainBundleResource = /** @class */ (function (_super) {
var BundleResource = /** @class */ (function (_super) { var BundleResource = /** @class */ (function (_super) {
__extends$f(BundleResource, _super); __extends$f(BundleResource, _super);
function BundleResource(bundleName, fileName) { function BundleResource(bundleName, fileName) {
return _super.call(this, "bundle", "".concat(bundleName, "://").concat(fileName)) || this; return _super.call(this, "bundle", bundleName + "://" + fileName) || this;
} }
return BundleResource; return BundleResource;
}(iOSResource)); }(iOSResource));
var ArrayBufferResource = /** @class */ (function (_super) {
__extends$f(ArrayBufferResource, _super);
function ArrayBufferResource(data) {
var _this = _super.call(this, "arrayBuffer", uniqueId("buffer")) || this;
_this.data = data;
return _this;
}
ArrayBufferResource.prototype.toModel = function () {
var ret = _super.prototype.toModel.call(this);
ret.data = this.data;
return ret;
};
return ArrayBufferResource;
}(Resource));
var __extends$e = (undefined && undefined.__extends) || (function () { var __extends$e = (undefined && undefined.__extends) || (function () {
var extendStatics = function (d, b) { var extendStatics = function (d, b) {
@ -2508,7 +2522,7 @@ var List = /** @class */ (function (_super) {
List.prototype.getItem = function (itemIdx) { List.prototype.getItem = function (itemIdx) {
var view = this.renderItem(itemIdx); var view = this.renderItem(itemIdx);
view.superview = this; view.superview = this;
this.cachedViews.set("".concat(itemIdx), view); this.cachedViews.set("" + itemIdx, view);
return view; return view;
}; };
List.prototype.renderBunchedItems = function (start, length) { List.prototype.renderBunchedItems = function (start, length) {
@ -2642,7 +2656,7 @@ var Slider = /** @class */ (function (_super) {
Slider.prototype.getItem = function (itemIdx) { Slider.prototype.getItem = function (itemIdx) {
var view = this.renderPage(itemIdx); var view = this.renderPage(itemIdx);
view.superview = this; view.superview = this;
this.cachedViews.set("".concat(itemIdx), view); this.cachedViews.set("" + itemIdx, view);
return view; return view;
}; };
Slider.prototype.renderBunchedItems = function (start, length) { Slider.prototype.renderBunchedItems = function (start, length) {
@ -3006,7 +3020,7 @@ exports.jsx = void 0;
Reflect.set(e, "innerElement", children, e); Reflect.set(e, "innerElement", children, e);
} }
else { else {
throw new Error("Do not support ".concat(constructor.name, " for ").concat(children)); throw new Error("Do not support " + constructor.name + " for " + children);
} }
} }
return e; return e;
@ -3124,7 +3138,7 @@ var FlowLayout = /** @class */ (function (_super) {
FlowLayout.prototype.getItem = function (itemIdx) { FlowLayout.prototype.getItem = function (itemIdx) {
var view = this.renderItem(itemIdx); var view = this.renderItem(itemIdx);
view.superview = this; view.superview = this;
this.cachedViews.set("".concat(itemIdx), view); this.cachedViews.set("" + itemIdx, view);
return view; return view;
}; };
FlowLayout.prototype.renderBunchedItems = function (start, length) { FlowLayout.prototype.renderBunchedItems = function (start, length) {
@ -3805,7 +3819,7 @@ function navbar(context) {
} }
function internalScheme(context, panelClass) { function internalScheme(context, panelClass) {
return "_internal_://export?class=".concat(encodeURIComponent(panelClass.name), "&context=").concat(context.id); return "_internal_://export?class=" + encodeURIComponent(panelClass.name) + "&context=" + context.id;
} }
function navigator(context) { function navigator(context) {
var moduleName = "navigator"; var moduleName = "navigator";
@ -3845,9 +3859,9 @@ function transformRequest(request) {
if (request.params !== undefined) { if (request.params !== undefined) {
var queryStrings = []; var queryStrings = [];
for (var key in request.params) { for (var key in request.params) {
queryStrings.push("".concat(key, "=").concat(encodeURIComponent(request.params[key]))); queryStrings.push(key + "=" + encodeURIComponent(request.params[key]));
} }
request.url = "".concat(request.url).concat(url.indexOf('?') >= 0 ? '&' : '?').concat(queryStrings.join('&')); request.url = "" + request.url + (url.indexOf('?') >= 0 ? '&' : '?') + queryStrings.join('&');
} }
if (typeof request.data === 'object') { if (typeof request.data === 'object') {
request.data = JSON.stringify(request.data); request.data = JSON.stringify(request.data);
@ -4123,7 +4137,7 @@ function animate(context) {
} }
else { else {
return function (args) { return function (args) {
return Promise.reject("Cannot find panel in Context:".concat(context.id)); return Promise.reject("Cannot find panel in Context:" + context.id);
}; };
} }
} }
@ -4617,6 +4631,7 @@ exports.AlphaAnimation = AlphaAnimation;
exports.AndroidAssetsResource = AndroidAssetsResource; exports.AndroidAssetsResource = AndroidAssetsResource;
exports.AndroidResource = AndroidResource; exports.AndroidResource = AndroidResource;
exports.AnimationSet = AnimationSet; exports.AnimationSet = AnimationSet;
exports.ArrayBufferResource = ArrayBufferResource;
exports.AssetsResource = AssetsResource; exports.AssetsResource = AssetsResource;
exports.BOTTOM = BOTTOM; exports.BOTTOM = BOTTOM;
exports.BackgroundColorAnimation = BackgroundColorAnimation; exports.BackgroundColorAnimation = BackgroundColorAnimation;

View File

@ -1680,6 +1680,17 @@ class BundleResource extends iOSResource {
super("bundle", `${bundleName}://${fileName}`); super("bundle", `${bundleName}://${fileName}`);
} }
} }
class ArrayBufferResource extends Resource {
constructor(data) {
super("arrayBuffer", uniqueId("buffer"));
this.data = data;
}
toModel() {
const ret = super.toModel();
ret.data = this.data;
return ret;
}
}
var __decorate$b = (undefined && undefined.__decorate) || function (decorators, target, key, desc) { var __decorate$b = (undefined && undefined.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
@ -3518,6 +3529,7 @@ exports.AlphaAnimation = AlphaAnimation;
exports.AndroidAssetsResource = AndroidAssetsResource; exports.AndroidAssetsResource = AndroidAssetsResource;
exports.AndroidResource = AndroidResource; exports.AndroidResource = AndroidResource;
exports.AnimationSet = AnimationSet; exports.AnimationSet = AnimationSet;
exports.ArrayBufferResource = ArrayBufferResource;
exports.AssetsResource = AssetsResource; exports.AssetsResource = AssetsResource;
exports.BOTTOM = BOTTOM; exports.BOTTOM = BOTTOM;
exports.BackgroundColorAnimation = BackgroundColorAnimation; exports.BackgroundColorAnimation = BackgroundColorAnimation;

File diff suppressed because it is too large Load Diff

View File

@ -3208,6 +3208,17 @@ class BundleResource extends iOSResource {
super("bundle", `${bundleName}://${fileName}`); super("bundle", `${bundleName}://${fileName}`);
} }
} }
class ArrayBufferResource extends Resource {
constructor(data) {
super("arrayBuffer", uniqueId("buffer"));
this.data = data;
}
toModel() {
const ret = super.toModel();
ret.data = this.data;
return ret;
}
}
var __decorate$b = (undefined && undefined.__decorate) || function (decorators, target, key, desc) { var __decorate$b = (undefined && undefined.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
@ -5287,6 +5298,7 @@ exports.AlphaAnimation = AlphaAnimation;
exports.AndroidAssetsResource = AndroidAssetsResource; exports.AndroidAssetsResource = AndroidAssetsResource;
exports.AndroidResource = AndroidResource; exports.AndroidResource = AndroidResource;
exports.AnimationSet = AnimationSet; exports.AnimationSet = AnimationSet;
exports.ArrayBufferResource = ArrayBufferResource;
exports.AssetsResource = AssetsResource; exports.AssetsResource = AssetsResource;
exports.BOTTOM = BOTTOM; exports.BOTTOM = BOTTOM;
exports.BackgroundColorAnimation = BackgroundColorAnimation; exports.BackgroundColorAnimation = BackgroundColorAnimation;

View File

@ -74,12 +74,16 @@ function _wrappedValue(v) {
}; };
} }
else if (v instanceof Array) { else if (v instanceof Array) {
v.forEach(e => {
traverse(e);
});
return { return {
type: "array", type: "array",
value: JSON.stringify(v) value: JSON.stringify(v)
}; };
} }
else { else {
traverse(v);
return { return {
type: "object", type: "object",
value: JSON.stringify(v) value: JSON.stringify(v)
@ -92,6 +96,30 @@ function _wrappedValue(v) {
}; };
} }
} }
const cachedArrayBuffer = new Map;
let bufferId = 0;
function traverse(obj) {
if (obj instanceof ArrayBuffer) {
return;
}
if (obj instanceof Array) {
obj.forEach(e => { traverse(e); });
return;
}
Object.entries(obj).forEach(([k, v]) => {
if (typeof v !== "object") {
return;
}
if (v instanceof ArrayBuffer) {
const id = `__buffer_${++bufferId}`;
obj[k] = `__buffer_${_arrayBufferToBase64(v)}`;
cachedArrayBuffer.set(id, v);
}
else {
traverse(v);
}
});
}
function _rawValue(v) { function _rawValue(v) {
switch (v.type) { switch (v.type) {
case "number": case "number":

9
doric-js/index.d.ts vendored
View File

@ -1771,6 +1771,15 @@ declare module 'doric/lib/src/util/resource' {
export class BundleResource extends iOSResource { export class BundleResource extends iOSResource {
constructor(bundleName: string, fileName: string); constructor(bundleName: string, fileName: string);
} }
export class ArrayBufferResource extends Resource {
data: ArrayBuffer;
constructor(data: ArrayBuffer);
toModel(): {
resId: string;
type: string;
identifier: string;
};
}
} }
declare module 'doric/lib/src/pattern/candies' { declare module 'doric/lib/src/pattern/candies' {

View File

@ -94,11 +94,15 @@ function _wrappedValue(v: RawValue): WrappedValue {
value: _arrayBufferToBase64(v) value: _arrayBufferToBase64(v)
}; };
} else if (v instanceof Array) { } else if (v instanceof Array) {
v.forEach(e => {
traverse(e)
})
return { return {
type: "array", type: "array",
value: JSON.stringify(v) value: JSON.stringify(v)
}; };
} else { } else {
traverse(v)
return { return {
type: "object", type: "object",
value: JSON.stringify(v) value: JSON.stringify(v)
@ -111,6 +115,31 @@ function _wrappedValue(v: RawValue): WrappedValue {
}; };
} }
} }
const cachedArrayBuffer: Map<string, ArrayBuffer> = new Map;
let bufferId = 0;
function traverse(obj: object) {
if (obj instanceof ArrayBuffer) {
return
}
if (obj instanceof Array) {
obj.forEach(e => { traverse(e) })
return
}
Object.entries(obj).forEach(([k, v]) => {
if (typeof v !== "object") {
return
}
if (v instanceof ArrayBuffer) {
const id = `__buffer_${++bufferId}`;
(obj as any)[k] = `__buffer_${_arrayBufferToBase64(v)}`;
cachedArrayBuffer.set(id, v);
} else {
traverse(v)
}
})
}
function _rawValue(v: WrappedValue): RawValue { function _rawValue(v: WrappedValue): RawValue {
switch (v.type) { switch (v.type) {

View File

@ -12,6 +12,9 @@ declare type WrappedValue = {
declare function _arrayBufferToBase64(arrayBuffer: ArrayBuffer): string; declare function _arrayBufferToBase64(arrayBuffer: ArrayBuffer): string;
declare function _base64ToArrayBuffer(v: string): ArrayBufferLike; declare function _base64ToArrayBuffer(v: string): ArrayBufferLike;
declare function _wrappedValue(v: RawValue): WrappedValue; declare function _wrappedValue(v: RawValue): WrappedValue;
declare const cachedArrayBuffer: Map<string, ArrayBuffer>;
declare let bufferId: number;
declare function traverse(obj: object): void;
declare function _rawValue(v: WrappedValue): RawValue; declare function _rawValue(v: WrappedValue): RawValue;
declare function __injectGlobalObject(name: string, args: string): void; declare function __injectGlobalObject(name: string, args: string): void;
declare function __injectGlobalFunction(name: string): void; declare function __injectGlobalFunction(name: string): void;

View File

@ -72,12 +72,16 @@ function _wrappedValue(v) {
}; };
} }
else if (v instanceof Array) { else if (v instanceof Array) {
v.forEach(e => {
traverse(e);
});
return { return {
type: "array", type: "array",
value: JSON.stringify(v) value: JSON.stringify(v)
}; };
} }
else { else {
traverse(v);
return { return {
type: "object", type: "object",
value: JSON.stringify(v) value: JSON.stringify(v)
@ -90,6 +94,30 @@ function _wrappedValue(v) {
}; };
} }
} }
const cachedArrayBuffer = new Map;
let bufferId = 0;
function traverse(obj) {
if (obj instanceof ArrayBuffer) {
return;
}
if (obj instanceof Array) {
obj.forEach(e => { traverse(e); });
return;
}
Object.entries(obj).forEach(([k, v]) => {
if (typeof v !== "object") {
return;
}
if (v instanceof ArrayBuffer) {
const id = `__buffer_${++bufferId}`;
obj[k] = `__buffer_${_arrayBufferToBase64(v)}`;
cachedArrayBuffer.set(id, v);
}
else {
traverse(v);
}
});
}
function _rawValue(v) { function _rawValue(v) {
switch (v.type) { switch (v.type) {
case "number": case "number":

View File

@ -50,3 +50,12 @@ export declare class MainBundleResource extends iOSResource {
export declare class BundleResource extends iOSResource { export declare class BundleResource extends iOSResource {
constructor(bundleName: string, fileName: string); constructor(bundleName: string, fileName: string);
} }
export declare class ArrayBufferResource extends Resource {
data: ArrayBuffer;
constructor(data: ArrayBuffer);
toModel(): {
resId: string;
type: string;
identifier: string;
};
}

View File

@ -71,3 +71,14 @@ export class BundleResource extends iOSResource {
super("bundle", `${bundleName}://${fileName}`); super("bundle", `${bundleName}://${fileName}`);
} }
} }
export class ArrayBufferResource extends Resource {
constructor(data) {
super("arrayBuffer", uniqueId("buffer"));
this.data = data;
}
toModel() {
const ret = super.toModel();
ret.data = this.data;
return ret;
}
}

View File

@ -3282,6 +3282,17 @@ class BundleResource extends iOSResource {
super("bundle", `${bundleName}://${fileName}`); super("bundle", `${bundleName}://${fileName}`);
} }
} }
class ArrayBufferResource extends Resource {
constructor(data) {
super("arrayBuffer", uniqueId("buffer"));
this.data = data;
}
toModel() {
const ret = super.toModel();
ret.data = this.data;
return ret;
}
}
var __decorate$b = (undefined && undefined.__decorate) || function (decorators, target, key, desc) { var __decorate$b = (undefined && undefined.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
@ -5120,6 +5131,7 @@ exports.AlphaAnimation = AlphaAnimation;
exports.AndroidAssetsResource = AndroidAssetsResource; exports.AndroidAssetsResource = AndroidAssetsResource;
exports.AndroidResource = AndroidResource; exports.AndroidResource = AndroidResource;
exports.AnimationSet = AnimationSet; exports.AnimationSet = AnimationSet;
exports.ArrayBufferResource = ArrayBufferResource;
exports.AssetsResource = AssetsResource; exports.AssetsResource = AssetsResource;
exports.BOTTOM = BOTTOM; exports.BOTTOM = BOTTOM;
exports.BackgroundColorAnimation = BackgroundColorAnimation; exports.BackgroundColorAnimation = BackgroundColorAnimation;

File diff suppressed because one or more lines are too long