wzx 2 éve
szülő
commit
5895d7d591

+ 1 - 0
pkg/.gitignore

@@ -0,0 +1 @@
+*

+ 69 - 0
pkg/README.md

@@ -0,0 +1,69 @@
+<div align="center">
+
+  <h1><code>wasm-pack-template</code></h1>
+
+  <strong>A template for kick starting a Rust and WebAssembly project using <a href="https://github.com/rustwasm/wasm-pack">wasm-pack</a>.</strong>
+
+  <p>
+    <a href="https://travis-ci.org/rustwasm/wasm-pack-template"><img src="https://img.shields.io/travis/rustwasm/wasm-pack-template.svg?style=flat-square" alt="Build Status" /></a>
+  </p>
+
+  <h3>
+    <a href="https://rustwasm.github.io/docs/wasm-pack/tutorials/npm-browser-packages/index.html">Tutorial</a>
+    <span> | </span>
+    <a href="https://discordapp.com/channels/442252698964721669/443151097398296587">Chat</a>
+  </h3>
+
+  <sub>Built with 🦀🕸 by <a href="https://rustwasm.github.io/">The Rust and WebAssembly Working Group</a></sub>
+</div>
+
+## About
+
+[**📚 Read this template tutorial! 📚**][template-docs]
+
+This template is designed for compiling Rust libraries into WebAssembly and
+publishing the resulting package to NPM.
+
+Be sure to check out [other `wasm-pack` tutorials online][tutorials] for other
+templates and usages of `wasm-pack`.
+
+[tutorials]: https://rustwasm.github.io/docs/wasm-pack/tutorials/index.html
+[template-docs]: https://rustwasm.github.io/docs/wasm-pack/tutorials/npm-browser-packages/index.html
+
+## 🚴 Usage
+
+### 🐑 Use `cargo generate` to Clone this Template
+
+[Learn more about `cargo generate` here.](https://github.com/ashleygwilliams/cargo-generate)
+
+```
+cargo generate --git https://github.com/rustwasm/wasm-pack-template.git --name my-project
+cd my-project
+```
+
+### 🛠️ Build with `wasm-pack build`
+
+```
+wasm-pack build
+```
+
+### 🔬 Test in Headless Browsers with `wasm-pack test`
+
+```
+wasm-pack test --headless --firefox
+```
+
+### 🎁 Publish to NPM with `wasm-pack publish`
+
+```
+wasm-pack publish
+```
+
+## 🔋 Batteries Included
+
+* [`wasm-bindgen`](https://github.com/rustwasm/wasm-bindgen) for communicating
+  between WebAssembly and JavaScript.
+* [`console_error_panic_hook`](https://github.com/rustwasm/console_error_panic_hook)
+  for logging panic messages to the developer console.
+* [`wee_alloc`](https://github.com/rustwasm/wee_alloc), an allocator optimized
+  for small code size.

+ 93 - 0
pkg/common_wasm.d.ts

@@ -0,0 +1,93 @@
+/* tslint:disable */
+/* eslint-disable */
+/**
+*/
+export function greet(): void;
+/**
+* 解析地图包Zip
+* @param {Uint8Array} data
+* @returns {MapPackage}
+*/
+export function parse_map_package(data: Uint8Array): MapPackage;
+/**
+*/
+export class MapPackage {
+  free(): void;
+/**
+* 图上坐标转经纬度
+* @param {Offset} on_pic
+* @returns {Position}
+*/
+  pic_to_position(on_pic: Offset): Position;
+/**
+* 经纬度转图上坐标
+* @param {Position} position
+* @returns {Offset}
+*/
+  position_to_pic(position: Position): Offset;
+/**
+* 地图缩放后后像素尺寸,用于计算新尺寸下地理坐标
+*/
+  dst_size: Size;
+/**
+* 地图图片格式
+*/
+  readonly map_ext: string;
+/**
+* 地图图片
+*/
+  readonly map_image_data: Uint8Array;
+/**
+* 地图原始像素尺寸
+*/
+  readonly src_size: Size;
+}
+/**
+* 点在图片上的坐标,原点为左上角
+*/
+export class Offset {
+  free(): void;
+/**
+*/
+  constructor();
+/**
+*/
+  x: number;
+/**
+*/
+  y: number;
+}
+/**
+*/
+export class Position {
+  free(): void;
+/**
+*/
+  constructor();
+/**
+* 计算两点距离,单位:米
+* @param {Position} other
+* @returns {number}
+*/
+  distance_to(other: Position): number;
+/**
+*/
+  latitude: number;
+/**
+*/
+  longitude: number;
+}
+/**
+*/
+export class Size {
+  free(): void;
+/**
+*/
+  constructor();
+/**
+*/
+  height: number;
+/**
+*/
+  width: number;
+}

+ 4 - 0
pkg/common_wasm.js

@@ -0,0 +1,4 @@
+import * as wasm from "./common_wasm_bg.wasm";
+import { __wbg_set_wasm } from "./common_wasm_bg.js";
+__wbg_set_wasm(wasm);
+export * from "./common_wasm_bg.js";

+ 475 - 0
pkg/common_wasm_bg.js

@@ -0,0 +1,475 @@
+let wasm;
+export function __wbg_set_wasm(val) {
+    wasm = val;
+}
+
+
+const lTextDecoder = typeof TextDecoder === 'undefined' ? (0, module.require)('util').TextDecoder : TextDecoder;
+
+let cachedTextDecoder = new lTextDecoder('utf-8', { ignoreBOM: true, fatal: true });
+
+cachedTextDecoder.decode();
+
+let cachedUint8Memory0 = null;
+
+function getUint8Memory0() {
+    if (cachedUint8Memory0 === null || cachedUint8Memory0.byteLength === 0) {
+        cachedUint8Memory0 = new Uint8Array(wasm.memory.buffer);
+    }
+    return cachedUint8Memory0;
+}
+
+function getStringFromWasm0(ptr, len) {
+    return cachedTextDecoder.decode(getUint8Memory0().subarray(ptr, ptr + len));
+}
+
+const heap = new Array(128).fill(undefined);
+
+heap.push(undefined, null, true, false);
+
+let heap_next = heap.length;
+
+function addHeapObject(obj) {
+    if (heap_next === heap.length) heap.push(heap.length + 1);
+    const idx = heap_next;
+    heap_next = heap[idx];
+
+    heap[idx] = obj;
+    return idx;
+}
+
+function getObject(idx) { return heap[idx]; }
+
+function dropObject(idx) {
+    if (idx < 132) return;
+    heap[idx] = heap_next;
+    heap_next = idx;
+}
+
+function takeObject(idx) {
+    const ret = getObject(idx);
+    dropObject(idx);
+    return ret;
+}
+/**
+*/
+export function greet() {
+    wasm.greet();
+}
+
+let WASM_VECTOR_LEN = 0;
+
+function passArray8ToWasm0(arg, malloc) {
+    const ptr = malloc(arg.length * 1);
+    getUint8Memory0().set(arg, ptr / 1);
+    WASM_VECTOR_LEN = arg.length;
+    return ptr;
+}
+
+let cachedInt32Memory0 = null;
+
+function getInt32Memory0() {
+    if (cachedInt32Memory0 === null || cachedInt32Memory0.byteLength === 0) {
+        cachedInt32Memory0 = new Int32Array(wasm.memory.buffer);
+    }
+    return cachedInt32Memory0;
+}
+/**
+* 解析地图包Zip
+* @param {Uint8Array} data
+* @returns {MapPackage}
+*/
+export function parse_map_package(data) {
+    try {
+        const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
+        const ptr0 = passArray8ToWasm0(data, wasm.__wbindgen_malloc);
+        const len0 = WASM_VECTOR_LEN;
+        wasm.parse_map_package(retptr, ptr0, len0);
+        var r0 = getInt32Memory0()[retptr / 4 + 0];
+        var r1 = getInt32Memory0()[retptr / 4 + 1];
+        var r2 = getInt32Memory0()[retptr / 4 + 2];
+        if (r2) {
+            throw takeObject(r1);
+        }
+        return MapPackage.__wrap(r0);
+    } finally {
+        wasm.__wbindgen_add_to_stack_pointer(16);
+    }
+}
+
+function _assertClass(instance, klass) {
+    if (!(instance instanceof klass)) {
+        throw new Error(`expected instance of ${klass.name}`);
+    }
+    return instance.ptr;
+}
+
+function getArrayU8FromWasm0(ptr, len) {
+    return getUint8Memory0().subarray(ptr / 1, ptr / 1 + len);
+}
+
+const lTextEncoder = typeof TextEncoder === 'undefined' ? (0, module.require)('util').TextEncoder : TextEncoder;
+
+let cachedTextEncoder = new lTextEncoder('utf-8');
+
+const encodeString = (typeof cachedTextEncoder.encodeInto === 'function'
+    ? function (arg, view) {
+    return cachedTextEncoder.encodeInto(arg, view);
+}
+    : function (arg, view) {
+    const buf = cachedTextEncoder.encode(arg);
+    view.set(buf);
+    return {
+        read: arg.length,
+        written: buf.length
+    };
+});
+
+function passStringToWasm0(arg, malloc, realloc) {
+
+    if (realloc === undefined) {
+        const buf = cachedTextEncoder.encode(arg);
+        const ptr = malloc(buf.length);
+        getUint8Memory0().subarray(ptr, ptr + buf.length).set(buf);
+        WASM_VECTOR_LEN = buf.length;
+        return ptr;
+    }
+
+    let len = arg.length;
+    let ptr = malloc(len);
+
+    const mem = getUint8Memory0();
+
+    let offset = 0;
+
+    for (; offset < len; offset++) {
+        const code = arg.charCodeAt(offset);
+        if (code > 0x7F) break;
+        mem[ptr + offset] = code;
+    }
+
+    if (offset !== len) {
+        if (offset !== 0) {
+            arg = arg.slice(offset);
+        }
+        ptr = realloc(ptr, len, len = offset + arg.length * 3);
+        const view = getUint8Memory0().subarray(ptr + offset, ptr + len);
+        const ret = encodeString(arg, view);
+
+        offset += ret.written;
+    }
+
+    WASM_VECTOR_LEN = offset;
+    return ptr;
+}
+/**
+*/
+export class MapPackage {
+
+    static __wrap(ptr) {
+        const obj = Object.create(MapPackage.prototype);
+        obj.ptr = ptr;
+
+        return obj;
+    }
+
+    __destroy_into_raw() {
+        const ptr = this.ptr;
+        this.ptr = 0;
+
+        return ptr;
+    }
+
+    free() {
+        const ptr = this.__destroy_into_raw();
+        wasm.__wbg_mappackage_free(ptr);
+    }
+    /**
+    * 地图图片格式
+    * @returns {string}
+    */
+    get map_ext() {
+        try {
+            const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
+            wasm.mappackage_map_ext(retptr, this.ptr);
+            var r0 = getInt32Memory0()[retptr / 4 + 0];
+            var r1 = getInt32Memory0()[retptr / 4 + 1];
+            return getStringFromWasm0(r0, r1);
+        } finally {
+            wasm.__wbindgen_add_to_stack_pointer(16);
+            wasm.__wbindgen_free(r0, r1);
+        }
+    }
+    /**
+    * 地图原始像素尺寸
+    * @returns {Size}
+    */
+    get src_size() {
+        const ret = wasm.mappackage_src_size(this.ptr);
+        return Size.__wrap(ret);
+    }
+    /**
+    * 地图缩放后后像素尺寸,用于计算新尺寸下地理坐标
+    * @param {Size} size
+    */
+    set dst_size(size) {
+        _assertClass(size, Size);
+        var ptr0 = size.__destroy_into_raw();
+        wasm.mappackage_set_dst_size(this.ptr, ptr0);
+    }
+    /**
+    * 地图图片
+    * @returns {Uint8Array}
+    */
+    get map_image_data() {
+        try {
+            const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
+            wasm.mappackage_map_image_data(retptr, this.ptr);
+            var r0 = getInt32Memory0()[retptr / 4 + 0];
+            var r1 = getInt32Memory0()[retptr / 4 + 1];
+            var v0 = getArrayU8FromWasm0(r0, r1).slice();
+            wasm.__wbindgen_free(r0, r1 * 1);
+            return v0;
+        } finally {
+            wasm.__wbindgen_add_to_stack_pointer(16);
+        }
+    }
+    /**
+    * 图上坐标转经纬度
+    * @param {Offset} on_pic
+    * @returns {Position}
+    */
+    pic_to_position(on_pic) {
+        _assertClass(on_pic, Offset);
+        var ptr0 = on_pic.__destroy_into_raw();
+        const ret = wasm.mappackage_pic_to_position(this.ptr, ptr0);
+        return Position.__wrap(ret);
+    }
+    /**
+    * 经纬度转图上坐标
+    * @param {Position} position
+    * @returns {Offset}
+    */
+    position_to_pic(position) {
+        _assertClass(position, Position);
+        var ptr0 = position.__destroy_into_raw();
+        const ret = wasm.mappackage_position_to_pic(this.ptr, ptr0);
+        return Offset.__wrap(ret);
+    }
+}
+/**
+* 点在图片上的坐标,原点为左上角
+*/
+export class Offset {
+
+    static __wrap(ptr) {
+        const obj = Object.create(Offset.prototype);
+        obj.ptr = ptr;
+
+        return obj;
+    }
+
+    __destroy_into_raw() {
+        const ptr = this.ptr;
+        this.ptr = 0;
+
+        return ptr;
+    }
+
+    free() {
+        const ptr = this.__destroy_into_raw();
+        wasm.__wbg_offset_free(ptr);
+    }
+    /**
+    * @returns {number}
+    */
+    get x() {
+        const ret = wasm.__wbg_get_offset_x(this.ptr);
+        return ret;
+    }
+    /**
+    * @param {number} arg0
+    */
+    set x(arg0) {
+        wasm.__wbg_set_offset_x(this.ptr, arg0);
+    }
+    /**
+    * @returns {number}
+    */
+    get y() {
+        const ret = wasm.__wbg_get_offset_y(this.ptr);
+        return ret;
+    }
+    /**
+    * @param {number} arg0
+    */
+    set y(arg0) {
+        wasm.__wbg_set_offset_y(this.ptr, arg0);
+    }
+    /**
+    */
+    constructor() {
+        const ret = wasm.offset_new();
+        return Offset.__wrap(ret);
+    }
+}
+/**
+*/
+export class Position {
+
+    static __wrap(ptr) {
+        const obj = Object.create(Position.prototype);
+        obj.ptr = ptr;
+
+        return obj;
+    }
+
+    __destroy_into_raw() {
+        const ptr = this.ptr;
+        this.ptr = 0;
+
+        return ptr;
+    }
+
+    free() {
+        const ptr = this.__destroy_into_raw();
+        wasm.__wbg_position_free(ptr);
+    }
+    /**
+    * @returns {number}
+    */
+    get latitude() {
+        const ret = wasm.__wbg_get_offset_x(this.ptr);
+        return ret;
+    }
+    /**
+    * @param {number} arg0
+    */
+    set latitude(arg0) {
+        wasm.__wbg_set_offset_x(this.ptr, arg0);
+    }
+    /**
+    * @returns {number}
+    */
+    get longitude() {
+        const ret = wasm.__wbg_get_offset_y(this.ptr);
+        return ret;
+    }
+    /**
+    * @param {number} arg0
+    */
+    set longitude(arg0) {
+        wasm.__wbg_set_offset_y(this.ptr, arg0);
+    }
+    /**
+    */
+    constructor() {
+        const ret = wasm.offset_new();
+        return Position.__wrap(ret);
+    }
+    /**
+    * 计算两点距离,单位:米
+    * @param {Position} other
+    * @returns {number}
+    */
+    distance_to(other) {
+        _assertClass(other, Position);
+        var ptr0 = other.__destroy_into_raw();
+        const ret = wasm.position_distance_to(this.ptr, ptr0);
+        return ret;
+    }
+}
+/**
+*/
+export class Size {
+
+    static __wrap(ptr) {
+        const obj = Object.create(Size.prototype);
+        obj.ptr = ptr;
+
+        return obj;
+    }
+
+    __destroy_into_raw() {
+        const ptr = this.ptr;
+        this.ptr = 0;
+
+        return ptr;
+    }
+
+    free() {
+        const ptr = this.__destroy_into_raw();
+        wasm.__wbg_size_free(ptr);
+    }
+    /**
+    * @returns {number}
+    */
+    get width() {
+        const ret = wasm.__wbg_get_offset_x(this.ptr);
+        return ret;
+    }
+    /**
+    * @param {number} arg0
+    */
+    set width(arg0) {
+        wasm.__wbg_set_offset_x(this.ptr, arg0);
+    }
+    /**
+    * @returns {number}
+    */
+    get height() {
+        const ret = wasm.__wbg_get_offset_y(this.ptr);
+        return ret;
+    }
+    /**
+    * @param {number} arg0
+    */
+    set height(arg0) {
+        wasm.__wbg_set_offset_y(this.ptr, arg0);
+    }
+    /**
+    */
+    constructor() {
+        const ret = wasm.offset_new();
+        return Size.__wrap(ret);
+    }
+}
+
+export function __wbg_alert_43a45fac7dbd48cc(arg0, arg1) {
+    alert(getStringFromWasm0(arg0, arg1));
+};
+
+export function __wbindgen_error_new(arg0, arg1) {
+    const ret = new Error(getStringFromWasm0(arg0, arg1));
+    return addHeapObject(ret);
+};
+
+export function __wbg_new_abda76e883ba8a5f() {
+    const ret = new Error();
+    return addHeapObject(ret);
+};
+
+export function __wbg_stack_658279fe44541cf6(arg0, arg1) {
+    const ret = getObject(arg1).stack;
+    const ptr0 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
+    const len0 = WASM_VECTOR_LEN;
+    getInt32Memory0()[arg0 / 4 + 1] = len0;
+    getInt32Memory0()[arg0 / 4 + 0] = ptr0;
+};
+
+export function __wbg_error_f851667af71bcfc6(arg0, arg1) {
+    try {
+        console.error(getStringFromWasm0(arg0, arg1));
+    } finally {
+        wasm.__wbindgen_free(arg0, arg1);
+    }
+};
+
+export function __wbindgen_object_drop_ref(arg0) {
+    takeObject(arg0);
+};
+
+export function __wbindgen_throw(arg0, arg1) {
+    throw new Error(getStringFromWasm0(arg0, arg1));
+};
+

BIN
pkg/common_wasm_bg.wasm


+ 35 - 0
pkg/common_wasm_bg.wasm.d.ts

@@ -0,0 +1,35 @@
+/* tslint:disable */
+/* eslint-disable */
+export const memory: WebAssembly.Memory;
+export function parse_map_package(a: number, b: number, c: number): void;
+export function __wbg_mappackage_free(a: number): void;
+export function __wbg_offset_free(a: number): void;
+export function __wbg_get_offset_x(a: number): number;
+export function __wbg_set_offset_x(a: number, b: number): void;
+export function __wbg_get_offset_y(a: number): number;
+export function __wbg_set_offset_y(a: number, b: number): void;
+export function offset_new(): number;
+export function mappackage_map_ext(a: number, b: number): void;
+export function mappackage_src_size(a: number): number;
+export function mappackage_set_dst_size(a: number, b: number): void;
+export function mappackage_map_image_data(a: number, b: number): void;
+export function mappackage_pic_to_position(a: number, b: number): number;
+export function mappackage_position_to_pic(a: number, b: number): number;
+export function position_distance_to(a: number, b: number): number;
+export function __wbg_set_size_width(a: number, b: number): void;
+export function __wbg_set_size_height(a: number, b: number): void;
+export function __wbg_set_position_latitude(a: number, b: number): void;
+export function __wbg_set_position_longitude(a: number, b: number): void;
+export function __wbg_size_free(a: number): void;
+export function __wbg_position_free(a: number): void;
+export function __wbg_get_size_width(a: number): number;
+export function __wbg_get_size_height(a: number): number;
+export function __wbg_get_position_latitude(a: number): number;
+export function __wbg_get_position_longitude(a: number): number;
+export function greet(): void;
+export function size_new(): number;
+export function position_new(): number;
+export function __wbindgen_add_to_stack_pointer(a: number): number;
+export function __wbindgen_malloc(a: number): number;
+export function __wbindgen_free(a: number, b: number): void;
+export function __wbindgen_realloc(a: number, b: number, c: number): number;

+ 19 - 0
pkg/package.json

@@ -0,0 +1,19 @@
+{
+  "name": "common_wasm",
+  "collaborators": [
+    "周睿 <zhourui818@126.com>"
+  ],
+  "version": "0.1.0",
+  "files": [
+    "common_wasm_bg.wasm",
+    "common_wasm.js",
+    "common_wasm_bg.js",
+    "common_wasm.d.ts"
+  ],
+  "module": "common_wasm.js",
+  "types": "common_wasm.d.ts",
+  "sideEffects": [
+    "./common_wasm.js",
+    "./snippets/*"
+  ]
+}