diff --git a/packages/analysis/package.json b/packages/analysis/package.json
index e1f3b9d..dfcfe76 100644
--- a/packages/analysis/package.json
+++ b/packages/analysis/package.json
@@ -88,7 +88,7 @@
"@babel/core": "^7.19.6",
"@types/bytes": "^3.1.1",
"@types/d3": "^7.4.0",
- "@types/node": "^18.11.3",
+ "@types/node": "^18.11.4",
"del-cli": "^5.0.0",
"esno": "^0.16.3",
"pnpm": "^7.14.0",
diff --git a/packages/core/package.json b/packages/core/package.json
index b6638c3..fcfe6b1 100644
--- a/packages/core/package.json
+++ b/packages/core/package.json
@@ -87,7 +87,7 @@
"esbuild-wasm": "^0.15.12"
},
"devDependencies": {
- "@types/node": "^18.11.3",
+ "@types/node": "^18.11.4",
"cross-fetch": "^3.1.5",
"del-cli": "^5.0.0",
"esno": "^0.16.3",
diff --git a/packages/website/astro.config.ts b/packages/website/astro.config.ts
index f234575..7190f02 100644
--- a/packages/website/astro.config.ts
+++ b/packages/website/astro.config.ts
@@ -108,7 +108,7 @@ export default defineConfig({
clientsClaim: false,
// globDirectory: outDir,
- globPatterns: ["**/*.{html,js,css,svg,ttf,woff2,png,jpg,jpeg,wasm,ico,json}"], //
+ globPatterns: ["**/*.{html,js,css,svg,ttf,woff2,png,webp,jpg,jpeg,wasm,ico,json,xml}"], //
ignoreURLParametersMatching: [/index\.html\?(.*)/, /\\?(.*)/],
cleanupOutdatedCaches: true,
@@ -117,7 +117,7 @@ export default defineConfig({
{
// Match any request that starts with https://api.producthunt.com, https://api.countapi.xyz, https://opencollective.com, etc...
urlPattern:
- /^https:\/\/((?:api\.producthunt\.com)|(?:api\.countapi\.xyz)|(?:opencollective\.com)|(?:giscus\.bundlejs\.com)|(?:bundlejs\.com\/take-measurement))|(?:unpkg\.com)|(?:cdn\.skypack\.dev)|(?:(cdn\.)?esm\.sh)|(?:esm\.run)|(?:cdn\.jsdelivr\.net)|(?:deno\.land)|(?:raw\.githubusercontent\.com)/,
+ /^https:\/\/((?:api\.producthunt\.com)|(?:api\.countapi\.xyz)|(?:opencollective\.com)|(?:giscus\.bundlejs\.com)|(?:bundlejs\.com\/take-measurement))/,
// Apply a network-first strategy.
handler: "NetworkFirst",
method: "GET",
@@ -130,7 +130,7 @@ export default defineConfig({
{
// Match any request that ends with .png, .jpg, .jpeg, .svg, etc....
urlPattern:
- /workbox\-(.*)\.js|\.(?:png|jpg|jpeg|svg|webp|map|wasm|css)$|^https:\/\/(?:cdn\.polyfill\.io)/,
+ /workbox\-(.*)\.js|\.(?:png|jpg|jpeg|svg|webp|map|ts|wasm|css)$|^https:\/\/(?:cdn\.polyfill\.io)/,
// Apply a stale-while-revalidate strategy.
handler: "StaleWhileRevalidate",
method: "GET",
@@ -143,7 +143,7 @@ export default defineConfig({
{
// Cache `monaco-editor` etc...
urlPattern:
- /chunks\/(.*)$/,
+ /(?:chunks|assets|favicon|fonts|giscus)\/(.*)$/,
// Apply a network-first strategy.
handler: "CacheFirst",
method: "GET",
diff --git a/packages/website/package.json b/packages/website/package.json
index c6f49f4..bd789fe 100644
--- a/packages/website/package.json
+++ b/packages/website/package.json
@@ -37,7 +37,9 @@
"@astrojs/solid-js": "^1.2.1",
"@astrojs/tailwind": "^2.1.1",
"@babel/core": "^7.19.6",
- "@iconify/json": "^2.1.126",
+ "@iconify/json": "^2.1.127",
+ "@types/offscreencanvas": "^2019.7.0",
+ "@typescript/lib-dom": "npm:@types/web@^0.0.75",
"astro": "^1.5.2",
"astrojs-service-worker": "^0.0.8",
"babel-preset-solid": "^1.6.0",
diff --git a/packages/website/src/components/DocsSection/VisitCounter/Counter.tsx b/packages/website/src/components/DocsSection/VisitCounter/Counter.tsx
index 38371e9..6c37582 100644
--- a/packages/website/src/components/DocsSection/VisitCounter/Counter.tsx
+++ b/packages/website/src/components/DocsSection/VisitCounter/Counter.tsx
@@ -6,7 +6,7 @@ const [count, setCount] = createSignal("00000");
// countapi-js hit counter. It counts the number of times the website is loaded
(async () => {
- if (!PRODUCTION_MODE || !("document" in globalThis)) return;
+ if (!PRODUCTION_MODE || !("visualViewport" in globalThis)) return;
try {
const { value } = await hit("bundle.js.org", "visits");
setCount(`${value}`);
diff --git a/packages/website/src/components/MainSection/EditorSection/Console.tsx b/packages/website/src/components/MainSection/EditorSection/Console.tsx
index dc0e421..15bf422 100644
--- a/packages/website/src/components/MainSection/EditorSection/Console.tsx
+++ b/packages/website/src/components/MainSection/EditorSection/Console.tsx
@@ -1,5 +1,5 @@
import type { ComponentProps } from "solid-js";
-import { createEffect, createSignal } from "solid-js";
+import { createEffect, createSignal, For } from "solid-js";
import { ConsoleButtons } from "./ConsoleButtons";
import { Log } from "./ConsoleLogs";
@@ -13,17 +13,11 @@ export function addLogs(...args: unknown[]) {
setLogsList([...logsList(), ...args]);
}
-if ("document" in globalThis) {
+if ("visualViewport" in globalThis) {
expose(addLogs, TASK_RUNNER);
}
export function Console(props?: ComponentProps<"div">) {
- createEffect(() => {
- if ("document" in globalThis) {
- console.log(logsList());
- }
- });
-
return (
@@ -31,14 +25,18 @@ export function Console(props?: ComponentProps<"div">) {
- {/*
-
- No logs...
-
-
*/}
-
-
Class
+
+
+ No logs...
+
+
+ }>
+ {(value) => (
+ {value.data}
+ )}
+
{/*
What do you mean?
diff --git a/packages/website/src/components/MainSection/EditorSection/Editor.tsx b/packages/website/src/components/MainSection/EditorSection/Editor.tsx
index 7701d54..b28c9d1 100644
--- a/packages/website/src/components/MainSection/EditorSection/Editor.tsx
+++ b/packages/website/src/components/MainSection/EditorSection/Editor.tsx
@@ -9,8 +9,8 @@ import { state, setState, initial } from "../../../scripts/utils/store";
import { getShareURLValues } from "../../../scripts/utils/get-initial";
import { createShareURL } from "../../../scripts/utils/share";
-const { configValue: configInitialValue } = "document" in globalThis && getShareURLValues();
-const [monaco] = "document" in globalThis ? createResource(() => {
+const { configValue: configInitialValue } = "visualViewport" in globalThis && getShareURLValues();
+const [monaco] = "visualViewport" in globalThis ? createResource(() => {
return import("../../../scripts/modules/monaco");
}) : [];
diff --git a/packages/website/src/components/MainSection/EditorSection/EditorButtons.tsx b/packages/website/src/components/MainSection/EditorSection/EditorButtons.tsx
index da5065d..70b69d7 100644
--- a/packages/website/src/components/MainSection/EditorSection/EditorButtons.tsx
+++ b/packages/website/src/components/MainSection/EditorSection/EditorButtons.tsx
@@ -78,7 +78,7 @@ export function EditorButtons() {
URL.revokeObjectURL(blobUrl);
}
- const media = ("document" in globalThis) && globalThis?.matchMedia("(max-width: 410px)");
+ const media = ("visualViewport" in globalThis) && globalThis?.matchMedia("(max-width: 410px)");
const [placement, setPlacement] = createSignal(media?.matches ? "bottom" : "top");
function mediaQueryRun(e?: MediaQueryListEvent) {
setPlacement(e?.matches ? "bottom" : "top");
diff --git a/packages/website/src/components/MainSection/SearchSection/Result.tsx b/packages/website/src/components/MainSection/SearchSection/Result.tsx
index 61d7111..d2c8591 100644
--- a/packages/website/src/components/MainSection/SearchSection/Result.tsx
+++ b/packages/website/src/components/MainSection/SearchSection/Result.tsx
@@ -9,6 +9,7 @@ import { createTextSwitch } from "../../../hooks/text-switch";
import Anchor from "../../../components/Anchor";
import Button from "../../../components/Button";
+import { inputModelResetValue } from "../../../scripts/utils/get-initial";
export interface SearchResultProps extends ComponentProps<"div"> {
type?: string;
@@ -33,27 +34,27 @@ export function SearchResult(props?: SearchResultProps) {
const BtnText = createTextSwitch(["Add Module", "Added!"]);
// When user clicks the "Add Module button" give the user some feedback
- function onClick() {
- (async () => {
- toast.success(`Added ${_package}`);
- await BtnText.switch("next");
-
- const inputValue = state.monaco.models.input.getValue();
- const inputInitialValue = state.monaco.initialValue.input;
-
- // Ths initial values starting comment
- const startingComment = inputInitialValue.split("\n")[0];
-
- state.monaco.models.input.setValue(
- // If the input model has change from it's initial value then
- // add the module under the rest of the code
- // Otherwise, replace the input model value with the new export
- (inputValue !== inputInitialValue ? inputValue : startingComment)?.trim() +
- `\nexport * from "${_package}";`
- );
-
- await BtnText.switch("initial", 500);
- })();
+ async function onClick() {
+ toast.success(`Added ${_package}`);
+ await BtnText.switch("next");
+
+ const inputValue = state.monaco.models.input.getValue();
+ const inputInitialValue = state.monaco.initialValue.input ?? inputModelResetValue;
+
+ // Ths initial values starting comment
+ const startingComment = inputInitialValue.split("\n")[0];
+
+ console.log({ _package })
+
+ state.monaco.models.input.setValue(
+ // If the input model has change from it's initial value then
+ // add the module under the rest of the code
+ // Otherwise, replace the input model value with the new export
+ (inputValue !== inputInitialValue ? inputValue : startingComment)?.trim() +
+ `\nexport * from "${_package}";`
+ );
+
+ await BtnText.switch("initial", 500);
}
return (
diff --git a/packages/website/src/components/OfflineBanner.tsx b/packages/website/src/components/OfflineBanner.tsx
index e55500d..2bc52c3 100644
--- a/packages/website/src/components/OfflineBanner.tsx
+++ b/packages/website/src/components/OfflineBanner.tsx
@@ -4,7 +4,7 @@ import OfflineIcon from "~icons/fluent/cloud-offline-24-regular";
const [isOnline, setIsOnline] = createSignal(true);
-if ("document" in globalThis) {
+if ("visualViewport" in globalThis) {
setIsOnline(navigator.onLine);
globalThis.addEventListener("online", () => {
diff --git a/packages/website/src/components/ThemeSwitch.tsx b/packages/website/src/components/ThemeSwitch.tsx
index 6bf325f..cf357a7 100644
--- a/packages/website/src/components/ThemeSwitch.tsx
+++ b/packages/website/src/components/ThemeSwitch.tsx
@@ -3,7 +3,7 @@ import { themeSet, themeGet } from "../scripts/theme";
import { onMount } from "solid-js";
let html: HTMLHtmlElement;
-if ("document" in globalThis) {
+if ("visualViewport" in globalThis) {
html = html ?? document.querySelector("html");
}
diff --git a/packages/website/src/env.ts b/packages/website/src/env.ts
index d5e01a6..dd7d1b5 100644
--- a/packages/website/src/env.ts
+++ b/packages/website/src/env.ts
@@ -1,5 +1,5 @@
export const env = import.meta.env;
export const ENABLE_SW = env.PROD;
-export const USE_SHAREDWORKER = env.PROD;
+export const USE_SHAREDWORKER = true ?? env.PROD;
export const PRODUCTION_MODE = env.PROD;
\ No newline at end of file
diff --git a/packages/website/src/hooks/roving-index.ts b/packages/website/src/hooks/roving-index.ts
index 722744d..eb8a17e 100644
--- a/packages/website/src/hooks/roving-index.ts
+++ b/packages/website/src/hooks/roving-index.ts
@@ -117,7 +117,7 @@ const focusNextItem = rover => {
rx.index = rx.targets.length - 1;
// use rover index state to find next
- const next = rx.targets[rx.index];
+ let next = rx.targets[rx.index];
// found something, activate it
next && activate(rover, next);
@@ -134,13 +134,14 @@ const focusPreviousItem = rover => {
rx.index = 0;
// use rover index state to find next
- const prev = rx.targets[rx.index];
+ let prev = rx.targets[rx.index];
// found something, activate it
prev && activate(rover, prev);
};
const activate = (rover, item) => {
+ if (!item) return;
const rx = state.get(rover);
// remove old tab index item
diff --git a/packages/website/src/hooks/tooltip.tsx b/packages/website/src/hooks/tooltip.tsx
index 08efa36..24b737e 100644
--- a/packages/website/src/hooks/tooltip.tsx
+++ b/packages/website/src/hooks/tooltip.tsx
@@ -40,7 +40,7 @@ export function ToolTip(props?: ComponentProps & { mobile?: string, as?: ke
mobile: "(max-width: 640px)"
}, newProps);
- const media = ("document" in globalThis) && globalThis?.matchMedia(mergedProps?.mobile);
+ const media = ("visualViewport" in globalThis) && globalThis?.matchMedia(mergedProps?.mobile);
function mediaQueryRun(e?: MediaQueryListEvent) {
if (e?.matches)
diff --git a/packages/website/src/scripts/index.ts b/packages/website/src/scripts/index.ts
index dc96f77..408dbe9 100644
--- a/packages/website/src/scripts/index.ts
+++ b/packages/website/src/scripts/index.ts
@@ -6,26 +6,28 @@ import { SharedWorkerPolyfill as SharedWorker } from "@okikio/sharedworker";
import * as Comlink from "comlink";
-export const TS_WORKER = "document" in globalThis && (
+import "./utils/transferhandle";
+
+export const TS_WORKER = "visualViewport" in globalThis && (
USE_SHAREDWORKER ?
new SharedWorker(new URL("./workers/typescript.ts", import.meta.url), { name: "typescript", type: "module" }) :
new Worker(new URL("./workers/typescript.ts", import.meta.url), { name: "typescript", type: "module" })
);
-export const EDITOR_WORKER = "document" in globalThis && (
+export const EDITOR_WORKER = "visualViewport" in globalThis && (
USE_SHAREDWORKER ?
new SharedWorker(new URL("./workers/editor.ts", import.meta.url), { name: "editor", type: "module" }) :
new Worker(new URL("./workers/editor.ts", import.meta.url), { name: "editor", type: "module" })
);
EDITOR_WORKER?.terminate?.();
-export const TASK_RUNNER = "document" in globalThis && (
+export const TASK_RUNNER = "visualViewport" in globalThis && (
USE_SHAREDWORKER ?
new SharedWorker(new URL("./workers/task-runner.ts", import.meta.url), { name: "task-runner", type: "module" }) :
new Worker(new URL("./workers/task-runner.ts", import.meta.url), { name: "task-runner", type: "module" })
);
-export const taskRunner = "document" in globalThis && Comlink.wrap(TASK_RUNNER);
+export const taskRunner = "visualViewport" in globalThis && Comlink.wrap(TASK_RUNNER);
setState("workers", { tasks: taskRunner });
globalThis?.addEventListener?.("pagehide", (event) => {
diff --git a/packages/website/src/scripts/modules/monaco.ts b/packages/website/src/scripts/modules/monaco.ts
index 268fdfe..0845158 100644
--- a/packages/website/src/scripts/modules/monaco.ts
+++ b/packages/website/src/scripts/modules/monaco.ts
@@ -18,7 +18,7 @@ import { mediaTheme, themeGet } from "../theme";
import { toLocaleDateString } from "../utils/locale-date-string";
import { configModelResetValue, getShareURLValues, inputModelResetValue, outputModelResetValue } from "../utils/get-initial";
-export { configModelResetValue };
+export { inputModelResetValue, outputModelResetValue, configModelResetValue };
// Since packaging is done by you, you need
// to instruct the editor how you named the
diff --git a/packages/website/src/scripts/utils/build.tsx b/packages/website/src/scripts/utils/build.tsx
index 983e943..f0ab7af 100644
--- a/packages/website/src/scripts/utils/build.tsx
+++ b/packages/website/src/scripts/utils/build.tsx
@@ -5,6 +5,7 @@ import { setState, state } from "./store";
import { taskRunner } from "../index";
import { outputModelResetValue } from "./get-initial";
+import { addLogs } from "../../components/MainSection/EditorSection/Console";
export const timeFormatter = new Intl.RelativeTimeFormat("en", {
style: "narrow",
@@ -63,6 +64,8 @@ export async function build() {
setState("bundleSize", result.size);
}
+ addLogs({ type: "info", data: `Build Done with a size of ${result.size} ${timeFormatter.format(elapsed, "seconds")}` })
+
// Signifier to no longer hold results in memory
result = null;
} catch (e) {
diff --git a/packages/website/src/scripts/utils/transferhandle.ts b/packages/website/src/scripts/utils/transferhandle.ts
new file mode 100644
index 0000000..5c66608
--- /dev/null
+++ b/packages/website/src/scripts/utils/transferhandle.ts
@@ -0,0 +1,86 @@
+import type { TransferHandler } from "comlink";
+import * as Comlink from "comlink";
+
+const TypedArray = Object.getPrototypeOf(Int8Array);
+const AudioData = globalThis.AudioData;
+const VideoFrame = globalThis.VideoFrame;
+const OffscreenCanvas = globalThis.OffscreenCanvas;
+const RTCDataChannel = globalThis.RTCDataChannel;
+
+type TypeTypedArray = Int8Array | Uint8Array | Uint8ClampedArray | Int16Array | Uint16Array | Int32Array | Uint32Array | Float32Array | Float64Array;
+type Transferable = ArrayBuffer | MessagePort | ReadableStream | WritableStream | TransformStream | typeof AudioData | ImageBitmap | typeof VideoFrame | OffscreenCanvas | RTCDataChannel;
+
+const isObject = (val: unknown): val is object =>
+ (typeof val === "object" && val !== null) || typeof val === "function";
+
+function isTypedArray(obj: unknown) {
+ return obj instanceof TypedArray || obj instanceof DataView;
+}
+
+function isTransferable(obj: unknown) {
+ return ("ArrayBuffer" in globalThis && obj instanceof ArrayBuffer) ||
+ ("MessagePort" in globalThis && obj instanceof MessagePort) ||
+ ("ReadableStream" in globalThis && obj instanceof ReadableStream) ||
+ ("WritableStream" in globalThis && obj instanceof WritableStream) ||
+ ("TransformStream" in globalThis && obj instanceof TransformStream) ||
+ ("AudioData" in globalThis && obj instanceof AudioData) ||
+ ("ImageBitmap" in globalThis && obj instanceof ImageBitmap) ||
+ ("VideoFrame" in globalThis && obj instanceof VideoFrame) ||
+ ("OffscreenCanvas" in globalThis && obj instanceof OffscreenCanvas) ||
+ ("RTCDataChannel" in globalThis && obj instanceof RTCDataChannel);
+}
+
+function filterOutDuplicates(array: T[]): T[] {
+ return [...new Set(array)];
+}
+
+// Get transferable objects from an object
+function getTransferables(obj: unknown): Transferable[] {
+ if (isTypedArray(obj)) {
+ const buffer = (obj as TypeTypedArray).buffer;
+ return [buffer];
+ } else if (isTransferable(obj)) {
+ return [obj as Transferable];
+ } else if (Array.isArray(obj)) {
+ const transferables = obj.flatMap(x => getTransferables(x));
+ return filterOutDuplicates(transferables);
+ } else if (isObject(obj)) {
+ const transferables = Object.values(obj).flatMap(x => getTransferables(x));
+ return filterOutDuplicates(transferables);
+ }
+
+ return [];
+}
+
+// Check is object contains transferable objects
+function hasTransferables(obj: unknown): boolean {
+ if (isTypedArray(obj) || isTransferable(obj)) {
+ return true;
+ } else if (Array.isArray(obj)) {
+ return obj.flatMap(x => hasTransferables(x)).includes(true);
+ } else if (isObject(obj)) {
+ return Object.values(obj).flatMap(x => hasTransferables(x)).includes(true);
+ } else {
+ return false;
+ }
+}
+
+/**
+ * Internal transfer handle to handle objects marked to proxy.
+ */
+const transferableTransferHandler: TransferHandler