@hanzogui/static-sync 2.0.0-rc.41-hanzoai.5

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,112 @@
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;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
+ // If the importer is in node compatibility mode or this is not an ESM
21
+ // file that has been converted to a CommonJS file using a Babel-
22
+ // compatible transform (i.e. "__esModule" has not been set), then set
23
+ // "default" to the CommonJS "module.exports" for node compatibility.
24
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25
+ mod
26
+ ));
27
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
+
29
+ // src/index.ts
30
+ var index_exports = {};
31
+ __export(index_exports, {
32
+ extractToClassNamesSync: () => extractToClassNamesSync,
33
+ extractToNativeSync: () => extractToNativeSync,
34
+ getBabelPlugin: () => getBabelPlugin,
35
+ getPragmaOptions: () => getPragmaOptions
36
+ });
37
+ module.exports = __toCommonJS(index_exports);
38
+ var import_synckit = require("synckit");
39
+ var import_node_url = require("node:url");
40
+ var import_meta = {};
41
+ var getWorkerPath = () => {
42
+ if (typeof import_meta !== "undefined" && import_meta.url) {
43
+ const workerPath = (0, import_node_url.fileURLToPath)(import_meta.resolve("@hanzogui/static/worker"));
44
+ return workerPath.replace(/\.mjs$/, ".js");
45
+ }
46
+ return require.resolve("@hanzogui/static/worker").replace(/\.mjs$/, ".js");
47
+ };
48
+ var runTaskSync = (0, import_synckit.createSyncFn)(getWorkerPath(), {
49
+ timeout: 6e4
50
+ // 60s timeout for sync operations
51
+ });
52
+ var getPragmaOptions = (props) => {
53
+ const { default: Static } = require("@hanzogui/static");
54
+ return Static.getPragmaOptions(props);
55
+ };
56
+ function extractToClassNamesSync(params) {
57
+ const { source, sourcePath = "", options, shouldPrintDebug = false } = params;
58
+ if (typeof source !== "string") {
59
+ throw new Error("`source` must be a string of javascript");
60
+ }
61
+ const task = {
62
+ type: "extractToClassNames",
63
+ source,
64
+ sourcePath,
65
+ options,
66
+ shouldPrintDebug
67
+ };
68
+ const result = runTaskSync(task);
69
+ if (!result.success) {
70
+ const errorMessage = [
71
+ `[hanzogui-extract] Error processing file: ${sourcePath || "(unknown)"}`,
72
+ ``,
73
+ result.error,
74
+ result.stack ? `
75
+ ${result.stack}` : ""
76
+ ].filter(Boolean).join("\n");
77
+ throw new Error(errorMessage);
78
+ }
79
+ return result.data;
80
+ }
81
+ function extractToNativeSync(sourceFileName, sourceCode, options) {
82
+ const task = {
83
+ type: "extractToNative",
84
+ sourceFileName,
85
+ sourceCode,
86
+ options
87
+ };
88
+ const result = runTaskSync(task);
89
+ if (!result.success) {
90
+ const errorMessage = [
91
+ `[hanzogui-extract] Error processing file: ${sourceFileName || "(unknown)"}`,
92
+ ``,
93
+ result.error,
94
+ result.stack ? `
95
+ ${result.stack}` : ""
96
+ ].filter(Boolean).join("\n");
97
+ throw new Error(errorMessage);
98
+ }
99
+ return result.data;
100
+ }
101
+ function getBabelPlugin() {
102
+ const { default: Static } = require("@hanzogui/static");
103
+ return Static.getBabelPlugin();
104
+ }
105
+ // Annotate the CommonJS export names for ESM import in node:
106
+ 0 && (module.exports = {
107
+ extractToClassNamesSync,
108
+ extractToNativeSync,
109
+ getBabelPlugin,
110
+ getPragmaOptions
111
+ });
112
+ //# sourceMappingURL=index.js.map
package/package.json ADDED
@@ -0,0 +1,42 @@
1
+ {
2
+ "name": "@hanzogui/static-sync",
3
+ "version": "2.0.0-rc.41-hanzoai.5",
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": "hanzogui-build --skip-native --bundle",
29
+ "watch": "bun run build --watch",
30
+ "clean": "hanzogui-build clean",
31
+ "clean:build": "hanzogui-build clean:build"
32
+ },
33
+ "dependencies": {
34
+ "@babel/core": "^7.25.2",
35
+ "@hanzogui/static": "2.0.0-rc.41-hanzoai.5",
36
+ "@hanzogui/types": "2.0.0-rc.41-hanzoai.5",
37
+ "synckit": "^0.9.2"
38
+ },
39
+ "devDependencies": {
40
+ "@hanzogui/build": "2.0.0-rc.41-hanzoai.5"
41
+ }
42
+ }
package/src/index.ts ADDED
@@ -0,0 +1,124 @@
1
+ /**
2
+ * @hanzogui/static-sync
3
+ *
4
+ * Synchronous API for Hanzogui 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 { HanzoguiOptions } from '@hanzogui/types'
13
+ import { createSyncFn } from 'synckit'
14
+ import { fileURLToPath } from 'node:url'
15
+
16
+ export type { ExtractedResponse, HanzoguiProjectInfo } from '@hanzogui/static'
17
+ export type { HanzoguiOptions } 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 Hanzogui components to className-based CSS for web (synchronous)
45
+ */
46
+ export function extractToClassNamesSync(params: {
47
+ source: string | Buffer
48
+ sourcePath?: string
49
+ options: HanzoguiOptions
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
+ `[hanzogui-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 Hanzogui components to React Native StyleSheet format (synchronous)
86
+ */
87
+ export function extractToNativeSync(
88
+ sourceFileName: string,
89
+ sourceCode: string,
90
+ options: HanzoguiOptions
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
+ `[hanzogui-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 Hanzogui 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 { HanzoguiOptions } from '@hanzogui/types';
12
+ export type { ExtractedResponse, HanzoguiProjectInfo } from '@hanzogui/static';
13
+ export type { HanzoguiOptions } from '@hanzogui/types';
14
+ export declare const getPragmaOptions: (props: {
15
+ source: string;
16
+ path: string;
17
+ }) => any;
18
+ /**
19
+ * Extract Hanzogui components to className-based CSS for web (synchronous)
20
+ */
21
+ export declare function extractToClassNamesSync(params: {
22
+ source: string | Buffer;
23
+ sourcePath?: string;
24
+ options: HanzoguiOptions;
25
+ shouldPrintDebug?: boolean | 'verbose';
26
+ }): any;
27
+ /**
28
+ * Extract Hanzogui components to React Native StyleSheet format (synchronous)
29
+ */
30
+ export declare function extractToNativeSync(sourceFileName: string, sourceCode: string, options: HanzoguiOptions): 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,eAAe,EAAE,MAAM,iBAAiB,CAAA;AAItD,YAAY,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAA;AAC9E,YAAY,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAA;AAoBtD,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,eAAe,CAAA;IACxB,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,eAAe,GACvB,eAAe,CAwBjB;AAED;;GAEG;AACH,wBAAgB,cAAc,QAI7B"}