@hanzogui/static-sync 2.0.0

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/dist/index.cjs ADDED
@@ -0,0 +1,95 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf, __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: !0 });
9
+ }, __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from == "object" || typeof from == "function")
11
+ for (let key of __getOwnPropNames(from))
12
+ !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
13
+ return to;
14
+ };
15
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
16
+ // If the importer is in node compatibility mode or this is not an ESM
17
+ // file that has been converted to a CommonJS file using a Babel-
18
+ // compatible transform (i.e. "__esModule" has not been set), then set
19
+ // "default" to the CommonJS "module.exports" for node compatibility.
20
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: !0 }) : target,
21
+ mod
22
+ )), __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: !0 }), mod);
23
+
24
+ // src/index.ts
25
+ var index_exports = {};
26
+ __export(index_exports, {
27
+ extractToClassNamesSync: () => extractToClassNamesSync,
28
+ extractToNativeSync: () => extractToNativeSync,
29
+ getBabelPlugin: () => getBabelPlugin,
30
+ getPragmaOptions: () => getPragmaOptions
31
+ });
32
+ module.exports = __toCommonJS(index_exports);
33
+ var import_synckit = require("synckit"), import_node_url = require("node:url"), import_meta = {}, getWorkerPath = () => typeof import_meta < "u" && import_meta.url ? (0, import_node_url.fileURLToPath)(import_meta.resolve("@hanzogui/static/worker")).replace(/\.mjs$/, ".js") : require.resolve("@hanzogui/static/worker").replace(/\.mjs$/, ".js"), runTaskSync = (0, import_synckit.createSyncFn)(getWorkerPath(), {
34
+ timeout: 6e4
35
+ // 60s timeout for sync operations
36
+ }), getPragmaOptions = (props) => {
37
+ let { default: Static } = require("@hanzogui/static");
38
+ return Static.getPragmaOptions(props);
39
+ };
40
+ function extractToClassNamesSync(params) {
41
+ let { source, sourcePath = "", options, shouldPrintDebug = !1 } = params;
42
+ if (typeof source != "string")
43
+ throw new Error("`source` must be a string of javascript");
44
+ let result = runTaskSync({
45
+ type: "extractToClassNames",
46
+ source,
47
+ sourcePath,
48
+ options,
49
+ shouldPrintDebug
50
+ });
51
+ if (!result.success) {
52
+ let errorMessage = [
53
+ `[gui-extract] Error processing file: ${sourcePath || "(unknown)"}`,
54
+ "",
55
+ result.error,
56
+ result.stack ? `
57
+ ${result.stack}` : ""
58
+ ].filter(Boolean).join(`
59
+ `);
60
+ throw new Error(errorMessage);
61
+ }
62
+ return result.data;
63
+ }
64
+ function extractToNativeSync(sourceFileName, sourceCode, options) {
65
+ let result = runTaskSync({
66
+ type: "extractToNative",
67
+ sourceFileName,
68
+ sourceCode,
69
+ options
70
+ });
71
+ if (!result.success) {
72
+ let errorMessage = [
73
+ `[gui-extract] Error processing file: ${sourceFileName || "(unknown)"}`,
74
+ "",
75
+ result.error,
76
+ result.stack ? `
77
+ ${result.stack}` : ""
78
+ ].filter(Boolean).join(`
79
+ `);
80
+ throw new Error(errorMessage);
81
+ }
82
+ return result.data;
83
+ }
84
+ function getBabelPlugin() {
85
+ let { default: Static } = require("@hanzogui/static");
86
+ return Static.getBabelPlugin();
87
+ }
88
+ // Annotate the CommonJS export names for ESM import in node:
89
+ 0 && (module.exports = {
90
+ extractToClassNamesSync,
91
+ extractToNativeSync,
92
+ getBabelPlugin,
93
+ getPragmaOptions
94
+ });
95
+ //# sourceMappingURL=index.js.map
package/package.json ADDED
@@ -0,0 +1,42 @@
1
+ {
2
+ "name": "@hanzogui/static-sync",
3
+ "version": "2.0.0",
4
+ "license": "MIT",
5
+ "source": "src/index.ts",
6
+ "files": [
7
+ "src",
8
+ "types",
9
+ "dist"
10
+ ],
11
+ "type": "commonjs",
12
+ "main": "dist",
13
+ "types": "./types/index.d.ts",
14
+ "exports": {
15
+ "./package.json": "./package.json",
16
+ ".": {
17
+ "types": "./types/index.d.ts",
18
+ "browser": "./dist/index.cjs",
19
+ "module": "./dist/index.cjs",
20
+ "import": "./dist/index.cjs",
21
+ "require": "./dist/index.cjs"
22
+ }
23
+ },
24
+ "publishConfig": {
25
+ "access": "public"
26
+ },
27
+ "scripts": {
28
+ "build": "hanzo-gui-build --skip-native --bundle",
29
+ "watch": "bun run build --watch",
30
+ "clean": "hanzo-gui-build clean",
31
+ "clean:build": "hanzo-gui-build clean:build"
32
+ },
33
+ "dependencies": {
34
+ "@babel/core": "^7.25.2",
35
+ "@hanzogui/static": "workspace:*",
36
+ "@hanzogui/types": "workspace:*",
37
+ "synckit": "^0.9.2"
38
+ },
39
+ "devDependencies": {
40
+ "@hanzogui/build": "workspace:*"
41
+ }
42
+ }
package/src/index.ts ADDED
@@ -0,0 +1,124 @@
1
+ /**
2
+ * @hanzogui/static-sync
3
+ *
4
+ * Synchronous API for Hanzo GUI static extraction using synckit.
5
+ * Wraps @hanzogui/static's worker implementation to provide sync APIs
6
+ * required by Babel plugins which cannot use async functions.
7
+ *
8
+ * This package uses synckit to convert async worker calls into synchronous ones.
9
+ */
10
+
11
+ import type { BabelFileResult } from '@babel/core'
12
+ import type { GuiOptions } from '@hanzogui/types'
13
+ import { createSyncFn } from 'synckit'
14
+ import { fileURLToPath } from 'node:url'
15
+
16
+ export type { ExtractedResponse, GuiProjectInfo } from '@hanzogui/static'
17
+ export type { GuiOptions } from '@hanzogui/types'
18
+
19
+ // Resolve worker path - works for both CJS and ESM
20
+ const getWorkerPath = () => {
21
+ // Use the CommonJS .js version which works for synckit
22
+ if (typeof import.meta !== 'undefined' && import.meta.url) {
23
+ const workerPath = fileURLToPath(import.meta.resolve('@hanzogui/static/worker'))
24
+ // Replace .mjs with .js for CommonJS compatibility
25
+ return workerPath.replace(/\.mjs$/, '.js')
26
+ }
27
+
28
+ // Fallback for CJS
29
+ return require.resolve('@hanzogui/static/worker').replace(/\.mjs$/, '.js')
30
+ }
31
+
32
+ // Create sync function that calls the worker's runTask function
33
+ const runTaskSync = createSyncFn(getWorkerPath(), {
34
+ timeout: 60000, // 60s timeout for sync operations
35
+ })
36
+
37
+ export const getPragmaOptions = (props: { source: string; path: string }) => {
38
+ // This doesn't need worker, just use static directly
39
+ const { default: Static } = require('@hanzogui/static')
40
+ return Static.getPragmaOptions(props)
41
+ }
42
+
43
+ /**
44
+ * Extract Hanzo GUI components to className-based CSS for web (synchronous)
45
+ */
46
+ export function extractToClassNamesSync(params: {
47
+ source: string | Buffer
48
+ sourcePath?: string
49
+ options: GuiOptions
50
+ shouldPrintDebug?: boolean | 'verbose'
51
+ }): any {
52
+ const { source, sourcePath = '', options, shouldPrintDebug = false } = params
53
+
54
+ if (typeof source !== 'string') {
55
+ throw new Error('`source` must be a string of javascript')
56
+ }
57
+
58
+ const task = {
59
+ type: 'extractToClassNames',
60
+ source,
61
+ sourcePath,
62
+ options,
63
+ shouldPrintDebug,
64
+ }
65
+
66
+ const result = runTaskSync(task) as any
67
+
68
+ if (!result.success) {
69
+ const errorMessage = [
70
+ `[gui-extract] Error processing file: ${sourcePath || '(unknown)'}`,
71
+ ``,
72
+ result.error,
73
+ result.stack ? `\n${result.stack}` : '',
74
+ ]
75
+ .filter(Boolean)
76
+ .join('\n')
77
+
78
+ throw new Error(errorMessage)
79
+ }
80
+
81
+ return result.data
82
+ }
83
+
84
+ /**
85
+ * Extract Hanzo GUI components to React Native StyleSheet format (synchronous)
86
+ */
87
+ export function extractToNativeSync(
88
+ sourceFileName: string,
89
+ sourceCode: string,
90
+ options: GuiOptions
91
+ ): BabelFileResult {
92
+ const task = {
93
+ type: 'extractToNative',
94
+ sourceFileName,
95
+ sourceCode,
96
+ options,
97
+ }
98
+
99
+ const result = runTaskSync(task) as any
100
+
101
+ if (!result.success) {
102
+ const errorMessage = [
103
+ `[gui-extract] Error processing file: ${sourceFileName || '(unknown)'}`,
104
+ ``,
105
+ result.error,
106
+ result.stack ? `\n${result.stack}` : '',
107
+ ]
108
+ .filter(Boolean)
109
+ .join('\n')
110
+
111
+ throw new Error(errorMessage)
112
+ }
113
+
114
+ return result.data
115
+ }
116
+
117
+ /**
118
+ * Get babel plugin that uses synchronous extraction
119
+ */
120
+ export function getBabelPlugin() {
121
+ // We need to wrap the babel plugin to use sync extraction
122
+ const { default: Static } = require('@hanzogui/static')
123
+ return Static.getBabelPlugin()
124
+ }
@@ -0,0 +1,35 @@
1
+ /**
2
+ * @hanzogui/static-sync
3
+ *
4
+ * Synchronous API for Hanzo GUI static extraction using synckit.
5
+ * Wraps @hanzogui/static's worker implementation to provide sync APIs
6
+ * required by Babel plugins which cannot use async functions.
7
+ *
8
+ * This package uses synckit to convert async worker calls into synchronous ones.
9
+ */
10
+ import type { BabelFileResult } from '@babel/core';
11
+ import type { GuiOptions } from '@hanzogui/types';
12
+ export type { ExtractedResponse, GuiProjectInfo } from '@hanzogui/static';
13
+ export type { GuiOptions } from '@hanzogui/types';
14
+ export declare const getPragmaOptions: (props: {
15
+ source: string;
16
+ path: string;
17
+ }) => any;
18
+ /**
19
+ * Extract Hanzo GUI components to className-based CSS for web (synchronous)
20
+ */
21
+ export declare function extractToClassNamesSync(params: {
22
+ source: string | Buffer;
23
+ sourcePath?: string;
24
+ options: GuiOptions;
25
+ shouldPrintDebug?: boolean | 'verbose';
26
+ }): any;
27
+ /**
28
+ * Extract Hanzo GUI components to React Native StyleSheet format (synchronous)
29
+ */
30
+ export declare function extractToNativeSync(sourceFileName: string, sourceCode: string, options: GuiOptions): BabelFileResult;
31
+ /**
32
+ * Get babel plugin that uses synchronous extraction
33
+ */
34
+ export declare function getBabelPlugin(): any;
35
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAClD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAIjD,YAAY,EAAE,iBAAiB,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAA;AACzE,YAAY,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAoBjD,eAAO,MAAM,gBAAgB,GAAI,OAAO;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,QAIvE,CAAA;AAED;;GAEG;AACH,wBAAgB,uBAAuB,CAAC,MAAM,EAAE;IAC9C,MAAM,EAAE,MAAM,GAAG,MAAM,CAAA;IACvB,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,OAAO,EAAE,UAAU,CAAA;IACnB,gBAAgB,CAAC,EAAE,OAAO,GAAG,SAAS,CAAA;CACvC,GAAG,GAAG,CA+BN;AAED;;GAEG;AACH,wBAAgB,mBAAmB,CACjC,cAAc,EAAE,MAAM,EACtB,UAAU,EAAE,MAAM,EAClB,OAAO,EAAE,UAAU,GAClB,eAAe,CAwBjB;AAED;;GAEG;AACH,wBAAgB,cAAc,QAI7B"}