gsap-offset-path 1.0.0 → 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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gsap-offset-path",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "description": "GSAP plugin for animating SVG path offsets using Clipper2 WASM",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",
@@ -13,11 +13,17 @@
13
13
  }
14
14
  },
15
15
  "files": [
16
- "dist/"
16
+ "dist/",
17
+ "wasm/pkg/clipper_offset.js",
18
+ "wasm/pkg/clipper_offset_bg.wasm"
17
19
  ],
18
20
  "scripts": {
21
+ "wasm:build": "cd wasm/clipper-offset && wasm-pack build --target web --out-dir pkg",
22
+ "wasm:build:release": "cd wasm/clipper-offset && wasm-pack build --target web --release --out-dir pkg",
23
+ "wasm:copy": "mkdir -p wasm/pkg && cp wasm/clipper-offset/pkg/clipper_offset_bg.wasm wasm/clipper-offset/pkg/clipper_offset.js wasm/pkg/",
24
+ "build:wasm": "pnpm wasm:build:release && pnpm wasm:copy",
19
25
  "build": "tsup",
20
- "prepublishOnly": "pnpm build"
26
+ "prepublishOnly": "pnpm build:wasm && pnpm build"
21
27
  },
22
28
  "keywords": [
23
29
  "gsap",
@@ -0,0 +1,356 @@
1
+ /* @ts-self-types="./clipper_offset.d.ts" */
2
+
3
+ /**
4
+ * @enum {0 | 1 | 2 | 3 | 4}
5
+ */
6
+ export const EndType = Object.freeze({
7
+ Polygon: 0, "0": "Polygon",
8
+ Joined: 1, "1": "Joined",
9
+ Butt: 2, "2": "Butt",
10
+ Square: 3, "3": "Square",
11
+ Round: 4, "4": "Round",
12
+ });
13
+
14
+ /**
15
+ * @enum {0 | 1 | 2 | 3}
16
+ */
17
+ export const JoinType = Object.freeze({
18
+ Square: 0, "0": "Square",
19
+ Bevel: 1, "1": "Bevel",
20
+ Round: 2, "2": "Round",
21
+ Miter: 3, "3": "Miter",
22
+ });
23
+
24
+ export function init_panic_hook() {
25
+ wasm.init_panic_hook();
26
+ }
27
+
28
+ /**
29
+ * @param {string} path_data
30
+ * @param {number} offset_amount
31
+ * @param {JoinType} join_type
32
+ * @param {EndType} end_type
33
+ * @param {number} miter_limit
34
+ * @param {number} arc_tolerance
35
+ * @param {number | null} [origin_x]
36
+ * @param {number | null} [origin_y]
37
+ * @returns {string}
38
+ */
39
+ export function offset_svg_path(path_data, offset_amount, join_type, end_type, miter_limit, arc_tolerance, origin_x, origin_y) {
40
+ let deferred3_0;
41
+ let deferred3_1;
42
+ try {
43
+ const ptr0 = passStringToWasm0(path_data, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
44
+ const len0 = WASM_VECTOR_LEN;
45
+ const ret = wasm.offset_svg_path(ptr0, len0, offset_amount, join_type, end_type, miter_limit, arc_tolerance, !isLikeNone(origin_x), isLikeNone(origin_x) ? 0 : origin_x, !isLikeNone(origin_y), isLikeNone(origin_y) ? 0 : origin_y);
46
+ var ptr2 = ret[0];
47
+ var len2 = ret[1];
48
+ if (ret[3]) {
49
+ ptr2 = 0; len2 = 0;
50
+ throw takeFromExternrefTable0(ret[2]);
51
+ }
52
+ deferred3_0 = ptr2;
53
+ deferred3_1 = len2;
54
+ return getStringFromWasm0(ptr2, len2);
55
+ } finally {
56
+ wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
57
+ }
58
+ }
59
+
60
+ /**
61
+ * @param {string} path_data
62
+ * @param {number} offset_amount
63
+ * @returns {string}
64
+ */
65
+ export function offset_svg_path_simple(path_data, offset_amount) {
66
+ let deferred3_0;
67
+ let deferred3_1;
68
+ try {
69
+ const ptr0 = passStringToWasm0(path_data, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
70
+ const len0 = WASM_VECTOR_LEN;
71
+ const ret = wasm.offset_svg_path_simple(ptr0, len0, offset_amount);
72
+ var ptr2 = ret[0];
73
+ var len2 = ret[1];
74
+ if (ret[3]) {
75
+ ptr2 = 0; len2 = 0;
76
+ throw takeFromExternrefTable0(ret[2]);
77
+ }
78
+ deferred3_0 = ptr2;
79
+ deferred3_1 = len2;
80
+ return getStringFromWasm0(ptr2, len2);
81
+ } finally {
82
+ wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
83
+ }
84
+ }
85
+
86
+ /**
87
+ * @returns {string}
88
+ */
89
+ export function test_simple_offset() {
90
+ let deferred2_0;
91
+ let deferred2_1;
92
+ try {
93
+ const ret = wasm.test_simple_offset();
94
+ var ptr1 = ret[0];
95
+ var len1 = ret[1];
96
+ if (ret[3]) {
97
+ ptr1 = 0; len1 = 0;
98
+ throw takeFromExternrefTable0(ret[2]);
99
+ }
100
+ deferred2_0 = ptr1;
101
+ deferred2_1 = len1;
102
+ return getStringFromWasm0(ptr1, len1);
103
+ } finally {
104
+ wasm.__wbindgen_free(deferred2_0, deferred2_1, 1);
105
+ }
106
+ }
107
+
108
+ /**
109
+ * @param {string} path_data
110
+ * @returns {boolean}
111
+ */
112
+ export function validate_svg_path(path_data) {
113
+ const ptr0 = passStringToWasm0(path_data, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
114
+ const len0 = WASM_VECTOR_LEN;
115
+ const ret = wasm.validate_svg_path(ptr0, len0);
116
+ return ret !== 0;
117
+ }
118
+
119
+ function __wbg_get_imports() {
120
+ const import0 = {
121
+ __proto__: null,
122
+ __wbg___wbindgen_throw_be289d5034ed271b: function(arg0, arg1) {
123
+ throw new Error(getStringFromWasm0(arg0, arg1));
124
+ },
125
+ __wbg_error_7534b8e9a36f1ab4: function(arg0, arg1) {
126
+ let deferred0_0;
127
+ let deferred0_1;
128
+ try {
129
+ deferred0_0 = arg0;
130
+ deferred0_1 = arg1;
131
+ console.error(getStringFromWasm0(arg0, arg1));
132
+ } finally {
133
+ wasm.__wbindgen_free(deferred0_0, deferred0_1, 1);
134
+ }
135
+ },
136
+ __wbg_new_8a6f238a6ece86ea: function() {
137
+ const ret = new Error();
138
+ return ret;
139
+ },
140
+ __wbg_stack_0ed75d68575b0f3c: function(arg0, arg1) {
141
+ const ret = arg1.stack;
142
+ const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
143
+ const len1 = WASM_VECTOR_LEN;
144
+ getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
145
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
146
+ },
147
+ __wbindgen_cast_0000000000000001: function(arg0, arg1) {
148
+ // Cast intrinsic for `Ref(String) -> Externref`.
149
+ const ret = getStringFromWasm0(arg0, arg1);
150
+ return ret;
151
+ },
152
+ __wbindgen_init_externref_table: function() {
153
+ const table = wasm.__wbindgen_externrefs;
154
+ const offset = table.grow(4);
155
+ table.set(0, undefined);
156
+ table.set(offset + 0, undefined);
157
+ table.set(offset + 1, null);
158
+ table.set(offset + 2, true);
159
+ table.set(offset + 3, false);
160
+ },
161
+ };
162
+ return {
163
+ __proto__: null,
164
+ "./clipper_offset_bg.js": import0,
165
+ };
166
+ }
167
+
168
+ let cachedDataViewMemory0 = null;
169
+ function getDataViewMemory0() {
170
+ if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) {
171
+ cachedDataViewMemory0 = new DataView(wasm.memory.buffer);
172
+ }
173
+ return cachedDataViewMemory0;
174
+ }
175
+
176
+ function getStringFromWasm0(ptr, len) {
177
+ ptr = ptr >>> 0;
178
+ return decodeText(ptr, len);
179
+ }
180
+
181
+ let cachedUint8ArrayMemory0 = null;
182
+ function getUint8ArrayMemory0() {
183
+ if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
184
+ cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
185
+ }
186
+ return cachedUint8ArrayMemory0;
187
+ }
188
+
189
+ function isLikeNone(x) {
190
+ return x === undefined || x === null;
191
+ }
192
+
193
+ function passStringToWasm0(arg, malloc, realloc) {
194
+ if (realloc === undefined) {
195
+ const buf = cachedTextEncoder.encode(arg);
196
+ const ptr = malloc(buf.length, 1) >>> 0;
197
+ getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
198
+ WASM_VECTOR_LEN = buf.length;
199
+ return ptr;
200
+ }
201
+
202
+ let len = arg.length;
203
+ let ptr = malloc(len, 1) >>> 0;
204
+
205
+ const mem = getUint8ArrayMemory0();
206
+
207
+ let offset = 0;
208
+
209
+ for (; offset < len; offset++) {
210
+ const code = arg.charCodeAt(offset);
211
+ if (code > 0x7F) break;
212
+ mem[ptr + offset] = code;
213
+ }
214
+ if (offset !== len) {
215
+ if (offset !== 0) {
216
+ arg = arg.slice(offset);
217
+ }
218
+ ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
219
+ const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
220
+ const ret = cachedTextEncoder.encodeInto(arg, view);
221
+
222
+ offset += ret.written;
223
+ ptr = realloc(ptr, len, offset, 1) >>> 0;
224
+ }
225
+
226
+ WASM_VECTOR_LEN = offset;
227
+ return ptr;
228
+ }
229
+
230
+ function takeFromExternrefTable0(idx) {
231
+ const value = wasm.__wbindgen_externrefs.get(idx);
232
+ wasm.__externref_table_dealloc(idx);
233
+ return value;
234
+ }
235
+
236
+ let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
237
+ cachedTextDecoder.decode();
238
+ const MAX_SAFARI_DECODE_BYTES = 2146435072;
239
+ let numBytesDecoded = 0;
240
+ function decodeText(ptr, len) {
241
+ numBytesDecoded += len;
242
+ if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {
243
+ cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
244
+ cachedTextDecoder.decode();
245
+ numBytesDecoded = len;
246
+ }
247
+ return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
248
+ }
249
+
250
+ const cachedTextEncoder = new TextEncoder();
251
+
252
+ if (!('encodeInto' in cachedTextEncoder)) {
253
+ cachedTextEncoder.encodeInto = function (arg, view) {
254
+ const buf = cachedTextEncoder.encode(arg);
255
+ view.set(buf);
256
+ return {
257
+ read: arg.length,
258
+ written: buf.length
259
+ };
260
+ };
261
+ }
262
+
263
+ let WASM_VECTOR_LEN = 0;
264
+
265
+ let wasmModule, wasm;
266
+ function __wbg_finalize_init(instance, module) {
267
+ wasm = instance.exports;
268
+ wasmModule = module;
269
+ cachedDataViewMemory0 = null;
270
+ cachedUint8ArrayMemory0 = null;
271
+ wasm.__wbindgen_start();
272
+ return wasm;
273
+ }
274
+
275
+ async function __wbg_load(module, imports) {
276
+ if (typeof Response === 'function' && module instanceof Response) {
277
+ if (typeof WebAssembly.instantiateStreaming === 'function') {
278
+ try {
279
+ return await WebAssembly.instantiateStreaming(module, imports);
280
+ } catch (e) {
281
+ const validResponse = module.ok && expectedResponseType(module.type);
282
+
283
+ if (validResponse && module.headers.get('Content-Type') !== 'application/wasm') {
284
+ console.warn("`WebAssembly.instantiateStreaming` failed because your server does not serve Wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\n", e);
285
+
286
+ } else { throw e; }
287
+ }
288
+ }
289
+
290
+ const bytes = await module.arrayBuffer();
291
+ return await WebAssembly.instantiate(bytes, imports);
292
+ } else {
293
+ const instance = await WebAssembly.instantiate(module, imports);
294
+
295
+ if (instance instanceof WebAssembly.Instance) {
296
+ return { instance, module };
297
+ } else {
298
+ return instance;
299
+ }
300
+ }
301
+
302
+ function expectedResponseType(type) {
303
+ switch (type) {
304
+ case 'basic': case 'cors': case 'default': return true;
305
+ }
306
+ return false;
307
+ }
308
+ }
309
+
310
+ function initSync(module) {
311
+ if (wasm !== undefined) return wasm;
312
+
313
+
314
+ if (module !== undefined) {
315
+ if (Object.getPrototypeOf(module) === Object.prototype) {
316
+ ({module} = module)
317
+ } else {
318
+ console.warn('using deprecated parameters for `initSync()`; pass a single object instead')
319
+ }
320
+ }
321
+
322
+ const imports = __wbg_get_imports();
323
+ if (!(module instanceof WebAssembly.Module)) {
324
+ module = new WebAssembly.Module(module);
325
+ }
326
+ const instance = new WebAssembly.Instance(module, imports);
327
+ return __wbg_finalize_init(instance, module);
328
+ }
329
+
330
+ async function __wbg_init(module_or_path) {
331
+ if (wasm !== undefined) return wasm;
332
+
333
+
334
+ if (module_or_path !== undefined) {
335
+ if (Object.getPrototypeOf(module_or_path) === Object.prototype) {
336
+ ({module_or_path} = module_or_path)
337
+ } else {
338
+ console.warn('using deprecated parameters for the initialization function; pass a single object instead')
339
+ }
340
+ }
341
+
342
+ if (module_or_path === undefined) {
343
+ module_or_path = new URL('clipper_offset_bg.wasm', import.meta.url);
344
+ }
345
+ const imports = __wbg_get_imports();
346
+
347
+ if (typeof module_or_path === 'string' || (typeof Request === 'function' && module_or_path instanceof Request) || (typeof URL === 'function' && module_or_path instanceof URL)) {
348
+ module_or_path = fetch(module_or_path);
349
+ }
350
+
351
+ const { instance, module } = await __wbg_load(await module_or_path, imports);
352
+
353
+ return __wbg_finalize_init(instance, module);
354
+ }
355
+
356
+ export { initSync, __wbg_init as default };
Binary file