@expofp/offline 0.0.0-experimental.d269d30
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/README.md +49 -0
- package/dist/cli.d.ts +3 -0
- package/dist/cli.js +80 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +3 -0
- package/dist/lib/abort-signal.d.ts +6 -0
- package/dist/lib/abort-signal.js +20 -0
- package/dist/lib/data-to-files.d.ts +8 -0
- package/dist/lib/data-to-files.js +36 -0
- package/dist/lib/download-offline-zip.d.ts +4 -0
- package/dist/lib/download-offline-zip.js +12 -0
- package/dist/lib/exec-script-in-sandbox.d.ts +3 -0
- package/dist/lib/exec-script-in-sandbox.js +50 -0
- package/dist/lib/generate-offline-data-legacy.d.ts +6 -0
- package/dist/lib/generate-offline-data-legacy.js +85 -0
- package/dist/lib/generate-offline-data.d.ts +6 -0
- package/dist/lib/generate-offline-data.js +90 -0
- package/dist/lib/generate-offline-map-data.d.ts +16 -0
- package/dist/lib/generate-offline-map-data.js +463 -0
- package/dist/lib/generate-runtime-files-data.d.ts +5 -0
- package/dist/lib/generate-runtime-files-data.js +16 -0
- package/dist/lib/offlinize-asset-url.d.ts +6 -0
- package/dist/lib/offlinize-asset-url.js +35 -0
- package/dist/lib/offlinize-assets-in-place.d.ts +6 -0
- package/dist/lib/offlinize-assets-in-place.js +139 -0
- package/dist/lib/offlinize-css-asset-text.d.ts +6 -0
- package/dist/lib/offlinize-css-asset-text.js +52 -0
- package/dist/lib/resolve-floorplan-dir.d.ts +8 -0
- package/dist/lib/resolve-floorplan-dir.js +34 -0
- package/dist/lib/save-offline-zip.d.ts +4 -0
- package/dist/lib/save-offline-zip.js +21 -0
- package/dist/lib/types.d.ts +18 -0
- package/dist/lib/types.js +1 -0
- package/package.json +39 -0
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { makeLocalPath } from '@expofp/utils';
|
|
2
|
+
import debug from 'debug';
|
|
3
|
+
const log = debug('efp:offline:offlinize-css-asset-text');
|
|
4
|
+
export async function offlinizeCssAssetText(css) {
|
|
5
|
+
const assets = [];
|
|
6
|
+
const urlRegex = /url\(\s*(['"]?)(.*?)\1\s*\)/g;
|
|
7
|
+
// Collect all URL matches first
|
|
8
|
+
const matches = [];
|
|
9
|
+
let regexMatch;
|
|
10
|
+
while ((regexMatch = urlRegex.exec(css)) !== null) {
|
|
11
|
+
matches.push({
|
|
12
|
+
match: regexMatch[0],
|
|
13
|
+
quote: regexMatch[1],
|
|
14
|
+
urlString: regexMatch[2],
|
|
15
|
+
index: regexMatch.index,
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
// Process all URLs and await their local paths
|
|
19
|
+
const replacements = await Promise.all(matches.map(async ({ match, quote, urlString }) => {
|
|
20
|
+
// Do not process data: URLs
|
|
21
|
+
if (urlString.startsWith('data:')) {
|
|
22
|
+
return { original: match, replacement: match };
|
|
23
|
+
}
|
|
24
|
+
// Only process if it's a valid URL
|
|
25
|
+
try {
|
|
26
|
+
const url = new URL(urlString);
|
|
27
|
+
const localPath = await makeLocalPath(url);
|
|
28
|
+
assets.push({
|
|
29
|
+
url,
|
|
30
|
+
targetFilePath: localPath,
|
|
31
|
+
});
|
|
32
|
+
log(`Offlinized CSS asset: ${urlString} -> ${localPath}`);
|
|
33
|
+
return {
|
|
34
|
+
original: match,
|
|
35
|
+
replacement: `url(${quote}${localPath}${quote})`,
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
catch {
|
|
39
|
+
console.warn(`Invalid URL in CSS: ${urlString}`);
|
|
40
|
+
return { original: match, replacement: match };
|
|
41
|
+
}
|
|
42
|
+
}));
|
|
43
|
+
// Apply all replacements
|
|
44
|
+
let processedCss = css;
|
|
45
|
+
for (const { original, replacement } of replacements) {
|
|
46
|
+
processedCss = processedCss.replace(original, replacement);
|
|
47
|
+
}
|
|
48
|
+
return {
|
|
49
|
+
css: processedCss,
|
|
50
|
+
assets,
|
|
51
|
+
};
|
|
52
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Locates the `@expofp/floorplan` browser build directory on disk and
|
|
3
|
+
* returns a `file://` URL string (with trailing slash) pointing at it.
|
|
4
|
+
*
|
|
5
|
+
* Throws if the package or its `bundle.json` cannot be found.
|
|
6
|
+
*/
|
|
7
|
+
export declare function resolveFloorplanDir(): Promise<string>;
|
|
8
|
+
//# sourceMappingURL=resolve-floorplan-dir.d.ts.map
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { createRequire } from 'node:module';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { pathToFileURL } from 'node:url';
|
|
4
|
+
import { importFsPromises } from '@expofp/utils';
|
|
5
|
+
/**
|
|
6
|
+
* Locates the `@expofp/floorplan` browser build directory on disk and
|
|
7
|
+
* returns a `file://` URL string (with trailing slash) pointing at it.
|
|
8
|
+
*
|
|
9
|
+
* Throws if the package or its `bundle.json` cannot be found.
|
|
10
|
+
*/
|
|
11
|
+
export async function resolveFloorplanDir() {
|
|
12
|
+
const require = createRequire(import.meta.url);
|
|
13
|
+
let pkgJsonPath;
|
|
14
|
+
try {
|
|
15
|
+
pkgJsonPath = require.resolve('@expofp/floorplan/package.json');
|
|
16
|
+
}
|
|
17
|
+
catch {
|
|
18
|
+
throw new Error('Could not find @expofp/floorplan. ' +
|
|
19
|
+
'Ensure it is installed (it should be a dependency of @expofp/offline).');
|
|
20
|
+
}
|
|
21
|
+
const pkgDir = path.dirname(pkgJsonPath);
|
|
22
|
+
const browserDir = path.join(pkgDir, 'dist', 'browser');
|
|
23
|
+
const bundleJsonPath = path.join(browserDir, 'bundle.json');
|
|
24
|
+
const fs = await importFsPromises();
|
|
25
|
+
try {
|
|
26
|
+
await fs.access(bundleJsonPath);
|
|
27
|
+
}
|
|
28
|
+
catch {
|
|
29
|
+
throw new Error(`Found @expofp/floorplan at ${pkgDir} but dist/browser/bundle.json is missing. ` +
|
|
30
|
+
'Ensure the package has been built (pnpm nx build-browser @expofp/floorplan).');
|
|
31
|
+
}
|
|
32
|
+
// Return file:// URL with trailing slash so new URL(file, base) works
|
|
33
|
+
return pathToFileURL(browserDir).href + '/';
|
|
34
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { Manifest, Ref } from '@expofp/data';
|
|
2
|
+
import type { OfflineOptions } from './types.js';
|
|
3
|
+
export declare function saveOfflineZip(manifest: Manifest | Ref<Manifest>, path: string, options: OfflineOptions): Promise<void>;
|
|
4
|
+
//# sourceMappingURL=save-offline-zip.d.ts.map
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { importFsPromises } from '@expofp/utils';
|
|
2
|
+
import debug from 'debug';
|
|
3
|
+
import { buildOfflineZip } from './generate-offline-data.js';
|
|
4
|
+
const log = debug('efp:offline:save-offline-zip');
|
|
5
|
+
export async function saveOfflineZip(manifest, path, options) {
|
|
6
|
+
if (typeof process === 'undefined' || !process.versions?.node) {
|
|
7
|
+
throw new Error('saveOfflineZip can only be used in a Node.js environment');
|
|
8
|
+
}
|
|
9
|
+
if (!path) {
|
|
10
|
+
throw new Error('Path is required to save the ZIP file');
|
|
11
|
+
}
|
|
12
|
+
if (!path.endsWith('.zip')) {
|
|
13
|
+
throw new Error('The specified path must end with .zip');
|
|
14
|
+
}
|
|
15
|
+
log('Saving offline ZIP bundle to', path);
|
|
16
|
+
const blob = await buildOfflineZip(manifest, options);
|
|
17
|
+
const arrayBuffer = await blob.arrayBuffer();
|
|
18
|
+
const fs = await importFsPromises();
|
|
19
|
+
await fs.writeFile(path, Buffer.from(arrayBuffer));
|
|
20
|
+
log('Saved offline ZIP bundle to', path);
|
|
21
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export type LocalData = LocalDataFetch | LocalDataText;
|
|
2
|
+
export interface LocalDataFetch {
|
|
3
|
+
url: URL;
|
|
4
|
+
targetFilePath: string;
|
|
5
|
+
}
|
|
6
|
+
export interface LocalDataText {
|
|
7
|
+
text: string;
|
|
8
|
+
targetFilePath: string;
|
|
9
|
+
}
|
|
10
|
+
export interface OfflineOptions {
|
|
11
|
+
signal?: AbortSignal;
|
|
12
|
+
runtimeBaseUrl: string;
|
|
13
|
+
offlineMap?: OfflineMapOptions;
|
|
14
|
+
}
|
|
15
|
+
export interface OfflineMapOptions {
|
|
16
|
+
mapSource?: string;
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/package.json
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@expofp/offline",
|
|
3
|
+
"version": "0.0.0-experimental.d269d30",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"description": "CLI tool for creating offline copies of ExpoFP floor plans",
|
|
6
|
+
"homepage": "https://developer.expofp.com/",
|
|
7
|
+
"license": "MIT",
|
|
8
|
+
"publishConfig": {
|
|
9
|
+
"access": "public"
|
|
10
|
+
},
|
|
11
|
+
"main": "./dist/index.js",
|
|
12
|
+
"module": "./dist/index.js",
|
|
13
|
+
"types": "./dist/index.d.ts",
|
|
14
|
+
"exports": {
|
|
15
|
+
"./package.json": "./package.json",
|
|
16
|
+
".": {
|
|
17
|
+
"@expofp/source": "./src/index.ts",
|
|
18
|
+
"types": "./dist/index.d.ts",
|
|
19
|
+
"import": "./dist/index.js",
|
|
20
|
+
"default": "./dist/index.js"
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
"bin": {
|
|
24
|
+
"expofp-offline": "./dist/cli.js"
|
|
25
|
+
},
|
|
26
|
+
"files": [
|
|
27
|
+
"dist",
|
|
28
|
+
"!**/*.tsbuildinfo",
|
|
29
|
+
"!**/*.map"
|
|
30
|
+
],
|
|
31
|
+
"dependencies": {
|
|
32
|
+
"debug": "^4.4.3",
|
|
33
|
+
"tslib": "^2.3.0",
|
|
34
|
+
"@expofp/data": "0.0.0-experimental.d269d30",
|
|
35
|
+
"@expofp/floorplan": "0.0.0-experimental.d269d30",
|
|
36
|
+
"@expofp/resolve": "0.0.0-experimental.d269d30",
|
|
37
|
+
"@expofp/utils": "0.0.0-experimental.d269d30"
|
|
38
|
+
}
|
|
39
|
+
}
|