@kamen/create-webapp 1.0.21 → 1.0.22
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/index.js +75 -0
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -100,4 +100,79 @@ export function sieveOfEratosthenes(max = 1 << 24) {
|
|
|
100
100
|
if (primes.has(p))
|
|
101
101
|
for (let i = p * p; i <= max; i += p) primes.delete(i);
|
|
102
102
|
return primes;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* @param {string|Function} code
|
|
107
|
+
* @param {string} [type='text/javascript']
|
|
108
|
+
* @returns {string}
|
|
109
|
+
*/
|
|
110
|
+
export function createResource(code, type = 'text/javascript') {
|
|
111
|
+
return URL.createObjectURL(new Blob([typeof code === 'function' ? code.toString() : code], {type}));
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* @param {string|Function} code
|
|
116
|
+
* @param {string} [tag='iframe']
|
|
117
|
+
* @param {string} [attribute='src']
|
|
118
|
+
* @param {string} [type='text/html']
|
|
119
|
+
* @param {Node} [container=document.body]
|
|
120
|
+
* @returns {Element}
|
|
121
|
+
*/
|
|
122
|
+
export function createResourceTag(code, tag = 'iframe', attribute = 'src', type = 'text/html', container = document.body) {
|
|
123
|
+
const element = document.createElement(tag);
|
|
124
|
+
element.setAttribute(attribute, createResource(code, type));
|
|
125
|
+
return container.appendChild(element);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* @param {string|Function} code
|
|
130
|
+
* @returns {Worker}
|
|
131
|
+
*/
|
|
132
|
+
export function createResourceClassicWorker(code) {
|
|
133
|
+
return new Worker(createResource(code), {type: 'classic'});
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* @param {string|Function} code
|
|
138
|
+
* @returns {Worker}
|
|
139
|
+
*/
|
|
140
|
+
export function createResourceModuleWorker(code) {
|
|
141
|
+
return new Worker(createResource(code), {type: 'module'});
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* @param {string|Function} code
|
|
146
|
+
* @param {Node} [container=document.head]
|
|
147
|
+
* @returns {HTMLScriptElement}
|
|
148
|
+
*/
|
|
149
|
+
export function createResourceClassicScript(code, container = document.head) {
|
|
150
|
+
return createResourceTag(code, 'script', 'type', 'text/javascript', container);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* @param {string|Function} code
|
|
155
|
+
* @param {Node} [container=document.head]
|
|
156
|
+
* @returns {HTMLScriptElement}
|
|
157
|
+
*/
|
|
158
|
+
export function createResourceModuleScript(code, container = document.head) {
|
|
159
|
+
return createResourceTag(code, 'script', 'type', 'module', container);
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* @param {string|Function} code
|
|
164
|
+
* @param {Node} [container=document.head]
|
|
165
|
+
* @returns {HTMLStyleElement}
|
|
166
|
+
*/
|
|
167
|
+
export function createResourceStyle(code, container = document.head) {
|
|
168
|
+
return createResourceTag(code, 'style', 'type', 'text/css', container);
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* @param {string|Function} code
|
|
173
|
+
* @param {Node} [container=document.body]
|
|
174
|
+
* @returns {HTMLIFrameElement}
|
|
175
|
+
*/
|
|
176
|
+
export function createResourceIframe(code, container = document.body) {
|
|
177
|
+
return createResourceTag(code, 'iframe', 'src', 'text/html', container);
|
|
103
178
|
}
|