@smplrspace/smplr-loader 2.4.1-beta.14 → 2.4.1-beta.3
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/.eslintignore +3 -0
- package/.eslintrc.js +42 -0
- package/package.json +3 -18
- package/src/generated/.gitkeep +0 -0
- package/src/index.ts +55 -0
- package/src/loadScript.ts +21 -0
- package/src/loadStylesheet.ts +22 -0
- package/{dist → src}/types.d.ts +0 -1
- package/tsconfig.json +17 -0
- package/dist/generated/smplr.d.ts +0 -10
- package/dist/index.d.ts +0 -5
- package/dist/index.js +0 -67
- package/dist/index.umd.cjs +0 -1
- package/dist/loadScript.d.ts +0 -2
- package/dist/loadStylesheet.d.ts +0 -1
package/.eslintignore
ADDED
package/.eslintrc.js
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
module.exports = {
|
|
2
|
+
env: {
|
|
3
|
+
browser: true,
|
|
4
|
+
es2021: true,
|
|
5
|
+
jest: true,
|
|
6
|
+
node: true,
|
|
7
|
+
},
|
|
8
|
+
parser: '@typescript-eslint/parser',
|
|
9
|
+
parserOptions: {
|
|
10
|
+
ecmaVersion: 'latest',
|
|
11
|
+
sourceType: 'module',
|
|
12
|
+
},
|
|
13
|
+
settings: {
|
|
14
|
+
'import/parsers': {
|
|
15
|
+
'@typescript-eslint/parser': ['.ts', '.tsx'],
|
|
16
|
+
},
|
|
17
|
+
'import/resolver': {
|
|
18
|
+
typescript: {},
|
|
19
|
+
},
|
|
20
|
+
},
|
|
21
|
+
extends: [
|
|
22
|
+
'eslint:recommended',
|
|
23
|
+
'plugin:@typescript-eslint/recommended',
|
|
24
|
+
'plugin:prettier/recommended',
|
|
25
|
+
'plugin:import/recommended',
|
|
26
|
+
'plugin:import/typescript',
|
|
27
|
+
],
|
|
28
|
+
plugins: ['@typescript-eslint', 'simple-import-sort'],
|
|
29
|
+
rules: {
|
|
30
|
+
'prettier/prettier': [
|
|
31
|
+
'error',
|
|
32
|
+
{
|
|
33
|
+
singleQuote: true,
|
|
34
|
+
semi: false,
|
|
35
|
+
printWidth: 120,
|
|
36
|
+
},
|
|
37
|
+
],
|
|
38
|
+
'import/newline-after-import': 'error',
|
|
39
|
+
'simple-import-sort/imports': 'error',
|
|
40
|
+
'simple-import-sort/exports': 'error',
|
|
41
|
+
},
|
|
42
|
+
}
|
package/package.json
CHANGED
|
@@ -1,22 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@smplrspace/smplr-loader",
|
|
3
|
-
"version": "2.4.1-beta.
|
|
3
|
+
"version": "2.4.1-beta.3",
|
|
4
4
|
"description": "NPM package to load a typed Smplr.js from CDN easily",
|
|
5
|
-
"
|
|
6
|
-
"files": [
|
|
7
|
-
"dist"
|
|
8
|
-
],
|
|
9
|
-
"main": "./dist/index.umd.cjs",
|
|
10
|
-
"module": "./dist/index.js",
|
|
11
|
-
"exports": {
|
|
12
|
-
".": {
|
|
13
|
-
"import": "./dist/index.js",
|
|
14
|
-
"require": "./dist/index.umd.cjs"
|
|
15
|
-
}
|
|
16
|
-
},
|
|
17
|
-
"types": "./dist/index.d.ts",
|
|
5
|
+
"main": "src/index.ts",
|
|
18
6
|
"scripts": {
|
|
19
|
-
"build": "yarn tsc && vite build",
|
|
20
7
|
"dev": "echo 'No dev'",
|
|
21
8
|
"serve": "echo 'No serve'",
|
|
22
9
|
"libtest": "echo 'No libtest'",
|
|
@@ -41,9 +28,7 @@
|
|
|
41
28
|
"eslint-plugin-import": "^2.26.0",
|
|
42
29
|
"eslint-plugin-prettier": "^4.2.1",
|
|
43
30
|
"prettier": "^2.7.1",
|
|
44
|
-
"typescript": "4.7.4"
|
|
45
|
-
"vite": "^4.1.1",
|
|
46
|
-
"vite-plugin-dts": "^1.7.1"
|
|
31
|
+
"typescript": "4.7.4"
|
|
47
32
|
},
|
|
48
33
|
"homepage": "https://www.smplrspace.com",
|
|
49
34
|
"keywords": [
|
|
File without changes
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { loadEsmModule, loadUmdScript } from './loadScript'
|
|
2
|
+
import { loadStylesheet } from './loadStylesheet'
|
|
3
|
+
import { Smplr } from './types'
|
|
4
|
+
|
|
5
|
+
export type { Smplr } from './types'
|
|
6
|
+
|
|
7
|
+
const SMPLR = {
|
|
8
|
+
umd: {
|
|
9
|
+
prod: 'https://app.smplrspace.com/lib/smplr.js',
|
|
10
|
+
dev: 'https://dev.smplrspace.com/lib/smplr.js',
|
|
11
|
+
local: 'http://localhost:3000/lib/smplr.umd.js',
|
|
12
|
+
},
|
|
13
|
+
esm: {
|
|
14
|
+
prod: 'https://app.smplrspace.com/lib/smplr.mjs',
|
|
15
|
+
dev: 'https://dev.smplrspace.com/lib/smplr.mjs',
|
|
16
|
+
local: 'http://localhost:3000/lib/smplr.mjs',
|
|
17
|
+
},
|
|
18
|
+
css: {
|
|
19
|
+
prod: 'https://app.smplrspace.com/lib/smplr.css',
|
|
20
|
+
dev: 'https://dev.smplrspace.com/lib/smplr.css',
|
|
21
|
+
local: 'http://localhost:3000/lib/style.css',
|
|
22
|
+
},
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
type BundleType = 'esm' | 'umd'
|
|
26
|
+
type Env = 'prod' | 'dev' | 'local'
|
|
27
|
+
|
|
28
|
+
export async function loadSmplrJs(bundle: BundleType = 'esm', env: Env = 'prod'): Promise<Smplr> {
|
|
29
|
+
try {
|
|
30
|
+
// we don't wait for the stylesheet, just start to load it
|
|
31
|
+
loadStylesheet(SMPLR.css[env])
|
|
32
|
+
} catch (e) {
|
|
33
|
+
console.warn('oops')
|
|
34
|
+
// ignore errors, they will be printed anyway
|
|
35
|
+
}
|
|
36
|
+
// load script
|
|
37
|
+
try {
|
|
38
|
+
if (bundle === 'esm') {
|
|
39
|
+
const smplr = (await loadEsmModule(SMPLR.esm[env])) as Smplr
|
|
40
|
+
console.log('loaded esm', smplr)
|
|
41
|
+
return smplr
|
|
42
|
+
} else {
|
|
43
|
+
await loadUmdScript(SMPLR.umd[env])
|
|
44
|
+
const smplr = window.smplr as Smplr
|
|
45
|
+
if (!smplr) {
|
|
46
|
+
throw new Error('Failed to load smplr.js')
|
|
47
|
+
}
|
|
48
|
+
console.log('loaded umd', smplr)
|
|
49
|
+
return smplr
|
|
50
|
+
}
|
|
51
|
+
} catch (error) {
|
|
52
|
+
console.error(error)
|
|
53
|
+
throw new Error('Failed to load smplr.js')
|
|
54
|
+
}
|
|
55
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export const loadUmdScript = (url: string) => {
|
|
2
|
+
return new Promise((resolve, reject) => {
|
|
3
|
+
try {
|
|
4
|
+
const scriptElement = document.createElement('script')
|
|
5
|
+
scriptElement.type = 'text/javascript'
|
|
6
|
+
scriptElement.async = true
|
|
7
|
+
scriptElement.src = url
|
|
8
|
+
scriptElement.addEventListener('load', () => {
|
|
9
|
+
resolve('ok')
|
|
10
|
+
})
|
|
11
|
+
scriptElement.addEventListener('error', () => {
|
|
12
|
+
reject(`Failed to load the script from ${url}`)
|
|
13
|
+
})
|
|
14
|
+
document.body.appendChild(scriptElement)
|
|
15
|
+
} catch (error) {
|
|
16
|
+
reject(error)
|
|
17
|
+
}
|
|
18
|
+
})
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export const loadEsmModule = (url: string) => import(url /* @vite-ignore */)
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export const loadStylesheet = (url: string) => {
|
|
2
|
+
return new Promise((resolve, reject) => {
|
|
3
|
+
try {
|
|
4
|
+
const linkElement = document.createElement('link')
|
|
5
|
+
linkElement.type = 'text/css'
|
|
6
|
+
linkElement.href = url
|
|
7
|
+
linkElement.rel = 'stylesheet'
|
|
8
|
+
linkElement.addEventListener('load', () => {
|
|
9
|
+
resolve('ok')
|
|
10
|
+
})
|
|
11
|
+
linkElement.addEventListener('error', () => {
|
|
12
|
+
const error = new Error(`Failed to load the stylesheet from ${url}`)
|
|
13
|
+
console.error(error)
|
|
14
|
+
reject(error)
|
|
15
|
+
})
|
|
16
|
+
document.head.appendChild(linkElement)
|
|
17
|
+
} catch (error) {
|
|
18
|
+
console.error(error)
|
|
19
|
+
reject(error)
|
|
20
|
+
}
|
|
21
|
+
})
|
|
22
|
+
}
|
package/{dist → src}/types.d.ts
RENAMED
package/tsconfig.json
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ESNext",
|
|
4
|
+
"lib": ["DOM", "DOM.Iterable", "ESNext"],
|
|
5
|
+
"allowJs": true,
|
|
6
|
+
"skipLibCheck": true,
|
|
7
|
+
"esModuleInterop": true,
|
|
8
|
+
"allowSyntheticDefaultImports": true,
|
|
9
|
+
"strict": true,
|
|
10
|
+
"module": "ESNext",
|
|
11
|
+
"moduleResolution": "Node",
|
|
12
|
+
"resolveJsonModule": true,
|
|
13
|
+
"isolatedModules": true,
|
|
14
|
+
"noEmit": true
|
|
15
|
+
},
|
|
16
|
+
"include": ["src"]
|
|
17
|
+
}
|
package/dist/index.d.ts
DELETED
package/dist/index.js
DELETED
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
const c = (r) => new Promise((o, s) => {
|
|
2
|
-
try {
|
|
3
|
-
const e = document.createElement("script");
|
|
4
|
-
e.type = "text/javascript", e.async = !0, e.src = r, e.addEventListener("load", () => {
|
|
5
|
-
o("ok");
|
|
6
|
-
}), e.addEventListener("error", () => {
|
|
7
|
-
s(`Failed to load the script from ${r}`);
|
|
8
|
-
}), document.body.appendChild(e);
|
|
9
|
-
} catch (e) {
|
|
10
|
-
s(e);
|
|
11
|
-
}
|
|
12
|
-
}), p = (r) => import(
|
|
13
|
-
r
|
|
14
|
-
/* @vite-ignore */
|
|
15
|
-
), a = (r) => new Promise((o, s) => {
|
|
16
|
-
try {
|
|
17
|
-
const e = document.createElement("link");
|
|
18
|
-
e.type = "text/css", e.href = r, e.rel = "stylesheet", e.addEventListener("load", () => {
|
|
19
|
-
o("ok");
|
|
20
|
-
}), e.addEventListener("error", () => {
|
|
21
|
-
const l = new Error(`Failed to load the stylesheet from ${r}`);
|
|
22
|
-
console.error(l), s(l);
|
|
23
|
-
}), document.head.appendChild(e);
|
|
24
|
-
} catch (e) {
|
|
25
|
-
console.error(e), s(e);
|
|
26
|
-
}
|
|
27
|
-
}), t = {
|
|
28
|
-
umd: {
|
|
29
|
-
prod: "https://app.smplrspace.com/lib/smplr.js",
|
|
30
|
-
dev: "https://dev.smplrspace.com/lib/smplr.js",
|
|
31
|
-
local: "http://localhost:3000/lib/smplr.umd.js"
|
|
32
|
-
},
|
|
33
|
-
esm: {
|
|
34
|
-
prod: "https://app.smplrspace.com/lib/smplr.mjs",
|
|
35
|
-
dev: "https://dev.smplrspace.com/lib/smplr.mjs",
|
|
36
|
-
local: "http://localhost:3000/lib/smplr.mjs"
|
|
37
|
-
},
|
|
38
|
-
css: {
|
|
39
|
-
prod: "https://app.smplrspace.com/lib/smplr.css",
|
|
40
|
-
dev: "https://dev.smplrspace.com/lib/smplr.css",
|
|
41
|
-
local: "http://localhost:3000/lib/style.css"
|
|
42
|
-
}
|
|
43
|
-
};
|
|
44
|
-
async function d(r = "esm", o = "prod") {
|
|
45
|
-
try {
|
|
46
|
-
a(t.css[o]);
|
|
47
|
-
} catch {
|
|
48
|
-
console.warn("oops");
|
|
49
|
-
}
|
|
50
|
-
try {
|
|
51
|
-
if (r === "esm") {
|
|
52
|
-
const s = await p(t.esm[o]);
|
|
53
|
-
return console.log("loaded esm", s), s;
|
|
54
|
-
} else {
|
|
55
|
-
await c(t.umd[o]);
|
|
56
|
-
const s = window.smplr;
|
|
57
|
-
if (!s)
|
|
58
|
-
throw new Error("Failed to load smplr.js");
|
|
59
|
-
return console.log("loaded umd", s), s;
|
|
60
|
-
}
|
|
61
|
-
} catch (s) {
|
|
62
|
-
throw console.error(s), new Error("Failed to load smplr.js");
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
export {
|
|
66
|
-
d as loadSmplrJs
|
|
67
|
-
};
|
package/dist/index.umd.cjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
(function(r,l){typeof exports=="object"&&typeof module<"u"?l(exports):typeof define=="function"&&define.amd?define(["exports"],l):(r=typeof globalThis<"u"?globalThis:r||self,l(r.SmplrLoader={}))})(this,function(r){"use strict";const l=o=>new Promise((t,s)=>{try{const e=document.createElement("script");e.type="text/javascript",e.async=!0,e.src=o,e.addEventListener("load",()=>{t("ok")}),e.addEventListener("error",()=>{s(`Failed to load the script from ${o}`)}),document.body.appendChild(e)}catch(e){s(e)}}),c=o=>import(o),n=o=>new Promise((t,s)=>{try{const e=document.createElement("link");e.type="text/css",e.href=o,e.rel="stylesheet",e.addEventListener("load",()=>{t("ok")}),e.addEventListener("error",()=>{const d=new Error(`Failed to load the stylesheet from ${o}`);console.error(d),s(d)}),document.head.appendChild(e)}catch(e){console.error(e),s(e)}}),p={umd:{prod:"https://app.smplrspace.com/lib/smplr.js",dev:"https://dev.smplrspace.com/lib/smplr.js",local:"http://localhost:3000/lib/smplr.umd.js"},esm:{prod:"https://app.smplrspace.com/lib/smplr.mjs",dev:"https://dev.smplrspace.com/lib/smplr.mjs",local:"http://localhost:3000/lib/smplr.mjs"},css:{prod:"https://app.smplrspace.com/lib/smplr.css",dev:"https://dev.smplrspace.com/lib/smplr.css",local:"http://localhost:3000/lib/style.css"}};async function m(o="esm",t="prod"){try{n(p.css[t])}catch{console.warn("oops")}try{if(o==="esm"){const s=await c(p.esm[t]);return console.log("loaded esm",s),s}else{await l(p.umd[t]);const s=window.smplr;if(!s)throw new Error("Failed to load smplr.js");return console.log("loaded umd",s),s}}catch(s){throw console.error(s),new Error("Failed to load smplr.js")}}r.loadSmplrJs=m,Object.defineProperty(r,Symbol.toStringTag,{value:"Module"})});
|
package/dist/loadScript.d.ts
DELETED
package/dist/loadStylesheet.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const loadStylesheet: (url: string) => Promise<unknown>;
|