@octane-xplat/bamboo 0.0.0-nightly.g2e22171

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2026 Alec Larson
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,40 @@
1
+ # `@octane-xplat/bamboo`
2
+
3
+ Shared [Bamboo](https://github.com/aleclarson/bamboo) CSS defaults for
4
+ Octane xplat apps. `xplatBambooConfig` scopes generation to the CSS subset
5
+ both NativeScript and browsers support (`xplatPortablePreset` and the
6
+ `vx-*` utility classes on framework token variables) and orders layers so
7
+ utilities sit under the app's own CSS. A Vite plugin emits the stylesheet.
8
+
9
+ ```sh
10
+ pnpm add -D @octane-xplat/bamboo
11
+ ```
12
+
13
+ Two entry points:
14
+
15
+ ```ts
16
+ // bamboo.config.ts
17
+ import { defineConfig } from '@bamboocss/dev'
18
+ import { xplatBambooConfig } from '@octane-xplat/bamboo'
19
+
20
+ export default defineConfig({
21
+ ...xplatBambooConfig,
22
+ include: ['src/**/*.ts'],
23
+ outdir: 'src/styled',
24
+ })
25
+ ```
26
+
27
+ Preflight is off by default and tokens land on `:root, .ns-root`. The
28
+ xplat NativeScript CSS transform unwraps the emitted `@layer` blocks for
29
+ native builds (the NS parser drops unknown at-rules); browsers keep the
30
+ layers, which is what lets app CSS stay unlayered on top.
31
+
32
+ ```ts
33
+ // Add this plugin alongside your app's existing renderer plugins.
34
+ import { xplatBamboo } from '@octane-xplat/bamboo/vite'
35
+
36
+ const webPlugins = xplatBamboo()
37
+ const nativePlugins = xplatBamboo({ native: true })
38
+ ```
39
+
40
+ Guide: [Styling screens](../../docs/app/styling.md).
package/package.json ADDED
@@ -0,0 +1,58 @@
1
+ {
2
+ "name": "@octane-xplat/bamboo",
3
+ "version": "0.0.0-nightly.g2e22171",
4
+ "description": "Bamboo CSS integration defaults for Octane xplat apps",
5
+ "keywords": [
6
+ "bamboo",
7
+ "css",
8
+ "nativescript",
9
+ "octane",
10
+ "xplat"
11
+ ],
12
+ "homepage": "https://github.com/octane-xplat/octane-xplat/tree/main/packages/bamboo",
13
+ "license": "MIT",
14
+ "repository": {
15
+ "type": "git",
16
+ "url": "https://github.com/octane-xplat/octane-xplat",
17
+ "directory": "packages/bamboo"
18
+ },
19
+ "files": [
20
+ "src",
21
+ "types",
22
+ "!src/**/*.test.*",
23
+ "!src/**/*.spec.*"
24
+ ],
25
+ "type": "module",
26
+ "exports": {
27
+ ".": {
28
+ "types": "./types/generated/config.d.ts",
29
+ "default": "./src/config.ts"
30
+ },
31
+ "./config": {
32
+ "types": "./types/generated/config.d.ts",
33
+ "default": "./src/config.ts"
34
+ },
35
+ "./vite": {
36
+ "types": "./types/generated/vite.d.ts",
37
+ "default": "./src/vite.ts"
38
+ }
39
+ },
40
+ "publishConfig": {
41
+ "access": "public"
42
+ },
43
+ "dependencies": {
44
+ "@bamboocss/preset-base": "1.56.2",
45
+ "@bamboocss/types": "1.56.2",
46
+ "@bamboocss/vite": "1.56.2"
47
+ },
48
+ "devDependencies": {
49
+ "typescript": "5.9.3"
50
+ },
51
+ "peerDependencies": {
52
+ "vite": ">=5"
53
+ },
54
+ "scripts": {
55
+ "test:packed": "node tests/packed-consumer.mjs",
56
+ "typegen": "tsc -p tsconfig.types.json"
57
+ }
58
+ }
package/src/config.ts ADDED
@@ -0,0 +1,112 @@
1
+ import { preset as presetBase } from '@bamboocss/preset-base'
2
+ import type { Preset, Theme, UserConfig, UtilityConfig } from '@bamboocss/types'
3
+
4
+ // Bamboo 1.56.2 has no flexWrap utility. Keep it outside this selected subset
5
+ // rather than promising a utility that cannot be generated.
6
+ const portableProperties = [
7
+ 'alignItems',
8
+ 'alignSelf',
9
+ 'backgroundColor',
10
+ 'borderColor',
11
+ 'borderRadius',
12
+ 'borderWidth',
13
+ 'color',
14
+ 'display',
15
+ 'flexDirection',
16
+ 'flexGrow',
17
+ 'flexShrink',
18
+ 'fontFamily',
19
+ 'fontSize',
20
+ 'fontWeight',
21
+ 'gap',
22
+ 'height',
23
+ 'justifyContent',
24
+ 'lineHeight',
25
+ 'margin',
26
+ 'marginBottom',
27
+ 'marginLeft',
28
+ 'marginRight',
29
+ 'marginTop',
30
+ 'maxHeight',
31
+ 'maxWidth',
32
+ 'minHeight',
33
+ 'minWidth',
34
+ 'padding',
35
+ 'paddingBottom',
36
+ 'paddingLeft',
37
+ 'paddingRight',
38
+ 'paddingTop',
39
+ 'textAlign',
40
+ 'width',
41
+ ] as const
42
+
43
+ const colors = Object.fromEntries(
44
+ ['danger', 'onprimary', 'primary', 'surface', 'surface-secondary', 'text', 'text-secondary'].map(
45
+ (name) => [name, { value: `var(--color-${name})` }],
46
+ ),
47
+ )
48
+
49
+ const spacing = Object.fromEntries(['4'].map((name) => [name, { value: `var(--space-${name})` }]))
50
+
51
+ const radii = Object.fromEntries(
52
+ ['sm', 'md', 'lg', 'xl'].map((name) => [name, { value: `var(--radius-${name})` }]),
53
+ )
54
+
55
+ const portableUtilities = Object.fromEntries(
56
+ portableProperties.map((property) => {
57
+ const config = presetBase.utilities[property]
58
+ if (!config) {
59
+ throw new Error(
60
+ `@octane-xplat/bamboo: missing portable utility "${property}" in @bamboocss/preset-base`,
61
+ )
62
+ }
63
+
64
+ // Bamboo's default margin scale includes `auto`, which NativeScript
65
+ // ignores; expose token spacing only in the shared preset.
66
+ return [property, property.startsWith('margin') ? { ...config, values: 'spacing' } : config]
67
+ }),
68
+ ) as UtilityConfig
69
+
70
+ const portableTheme = {
71
+ tokens: {
72
+ colors,
73
+ radii,
74
+ spacing,
75
+ },
76
+ } satisfies Theme
77
+
78
+ /**
79
+ * Utilities and tokens selected for the CSS subset shared by NativeScript and
80
+ * browsers. This intentionally omits Bamboo's full browser-oriented preset;
81
+ * apps can extend it when they have checked a property on their targets.
82
+ */
83
+ export const xplatPortablePreset: Preset = {
84
+ name: '@octane-xplat/bamboo/portable',
85
+ utilities: portableUtilities,
86
+ theme: portableTheme,
87
+ }
88
+
89
+ /**
90
+ * Bamboo defaults for apps using the shared Octane xplat stylesheet.
91
+ *
92
+ * Pass this object to `defineConfig` from `@bamboocss/dev`, then add the app's
93
+ * `include` and `outdir`. The shared UI stylesheet declares the matching layer
94
+ * order before `virtual:bamboo.css` is imported.
95
+ */
96
+ export const xplatBambooConfig = {
97
+ preflight: false,
98
+ cssVarRoot: ':root, .ns-root',
99
+ layers: {
100
+ reset: 'xplat.reset',
101
+ base: 'xplat.base',
102
+ tokens: 'xplat.tokens',
103
+ recipes: 'xplat.recipes',
104
+ utilities: 'xplat.utilities',
105
+ },
106
+ presets: [],
107
+ utilities: portableUtilities,
108
+ theme: portableTheme,
109
+ } satisfies Pick<
110
+ UserConfig,
111
+ 'preflight' | 'cssVarRoot' | 'layers' | 'presets' | 'utilities' | 'theme'
112
+ >
package/src/vite.ts ADDED
@@ -0,0 +1,116 @@
1
+ import { bamboocss, type BambooVitePluginOptions } from '@bamboocss/vite'
2
+ import type { Plugin } from 'vite'
3
+
4
+ function runBeforeNativeCss(plugin: Plugin | undefined, anchor: string) {
5
+ const hook = plugin?.generateBundle
6
+ if (plugin && typeof hook === 'function') {
7
+ plugin.generateBundle = { order: 'pre', handler: hook }
8
+ } else if (hook && typeof hook === 'object' && typeof hook.handler === 'function') {
9
+ hook.order = 'pre'
10
+ } else {
11
+ throw new Error(
12
+ `@octane-xplat/bamboo: native CSS adaptation requires ${anchor} with a generateBundle handler`,
13
+ )
14
+ }
15
+ }
16
+
17
+ export interface XplatBambooOptions extends BambooVitePluginOptions {
18
+ /** NativeScript consumes CSS assets in its own generateBundle hook. */
19
+ native?: boolean
20
+ }
21
+
22
+ /**
23
+ * Create Bamboo's Vite plugins for an Octane xplat app.
24
+ *
25
+ * Pass `cwd` and `configPath` when Bamboo's source/config root differs from
26
+ * Vite's app root, as it does in the shared harness.
27
+ */
28
+ export function xplatBamboo({ native = false, ...options }: XplatBambooOptions = {}) {
29
+ const plugins = bamboocss(options)
30
+
31
+ if (native) {
32
+ // Let Bamboo prune and validate the emitted asset before NativeScript's
33
+ // main-entry hook serializes it into the native bootstrap and removes it.
34
+ const cssPlugin = plugins.find((plugin) => plugin.name === 'bamboocss:css')
35
+ runBeforeNativeCss(cssPlugin, 'bamboocss:css')
36
+
37
+ let isBuild = false
38
+ plugins.push({
39
+ name: 'xplat-bamboo:nativescript-entry-graph',
40
+ enforce: 'post',
41
+ configResolved(config) {
42
+ isBuild = config.command === 'build'
43
+ },
44
+ buildEnd(error) {
45
+ if (!isBuild || error) {
46
+ return
47
+ }
48
+
49
+ // Inspect the graph, including cached modules in watch builds. A
50
+ // custom entry that already imports the sheet needs no injection.
51
+ if (![...this.getModuleIds()].some((id) => id.split('?')[0] === '\0virtual:bamboo.css')) {
52
+ this.error(
53
+ '@octane-xplat/bamboo: native entry graph is missing virtual:bamboo.css; expected virtual:entry-with-polyfills or an explicit stylesheet import',
54
+ )
55
+ }
56
+ },
57
+ transform(code, id) {
58
+ // @nativescript/vite builds from a generated entry
59
+ // (`virtual:entry-with-polyfills`). Under HMR that entry boots
60
+ // the app over HTTP instead of statically importing the app's
61
+ // main module, so `import 'virtual:bamboo.css'` there never
62
+ // enters the bundle's module graph — while class values still
63
+ // compile, tripping bamboocss's entry-graph check at buildEnd.
64
+ // Import the stylesheet from the generated entry itself so it
65
+ // is in the graph in every mode; the emitted asset then flows
66
+ // through the same generateBundle path as every other .css.
67
+ if (id !== '\0virtual:entry-with-polyfills' || code.includes('virtual:bamboo.css')) {
68
+ return
69
+ }
70
+
71
+ return { code: `${code}\nimport 'virtual:bamboo.css';\n`, map: null }
72
+ },
73
+ })
74
+
75
+ plugins.push({
76
+ name: 'xplat-bamboo:nativescript-output',
77
+ enforce: 'post',
78
+ options: {
79
+ order: 'post',
80
+ handler(inputOptions) {
81
+ const options = inputOptions as typeof inputOptions & {
82
+ output?: { plugins?: Plugin[] } | Array<{ plugins?: Plugin[] }>
83
+ }
84
+
85
+ const outputs = Array.isArray(options.output)
86
+ ? options.output
87
+ : options.output
88
+ ? [options.output]
89
+ : []
90
+
91
+ // Upstream installs one finalizer per configured output. With no
92
+ // output configured its options hook deliberately installs none.
93
+ for (const output of outputs) {
94
+ const finalizers = (output.plugins ?? [])
95
+ .flat(Infinity)
96
+ .filter((plugin): plugin is Plugin =>
97
+ Boolean(plugin && plugin.name?.startsWith('bamboocss:output-finalizer:')),
98
+ )
99
+
100
+ if (!finalizers.length) {
101
+ throw new Error(
102
+ '@octane-xplat/bamboo: native CSS adaptation requires a bamboocss:output-finalizer:* plugin for each configured output',
103
+ )
104
+ }
105
+
106
+ for (const finalizer of finalizers) {
107
+ runBeforeNativeCss(finalizer, finalizer.name)
108
+ }
109
+ }
110
+ },
111
+ },
112
+ })
113
+ }
114
+
115
+ return plugins
116
+ }
@@ -0,0 +1,46 @@
1
+ import type { Preset, UtilityConfig } from '@bamboocss/types';
2
+ /**
3
+ * Utilities and tokens selected for the CSS subset shared by NativeScript and
4
+ * browsers. This intentionally omits Bamboo's full browser-oriented preset;
5
+ * apps can extend it when they have checked a property on their targets.
6
+ */
7
+ export declare const xplatPortablePreset: Preset;
8
+ /**
9
+ * Bamboo defaults for apps using the shared Octane xplat stylesheet.
10
+ *
11
+ * Pass this object to `defineConfig` from `@bamboocss/dev`, then add the app's
12
+ * `include` and `outdir`. The shared UI stylesheet declares the matching layer
13
+ * order before `virtual:bamboo.css` is imported.
14
+ */
15
+ export declare const xplatBambooConfig: {
16
+ preflight: false;
17
+ cssVarRoot: string;
18
+ layers: {
19
+ reset: string;
20
+ base: string;
21
+ tokens: string;
22
+ recipes: string;
23
+ utilities: string;
24
+ };
25
+ presets: never[];
26
+ utilities: UtilityConfig;
27
+ theme: {
28
+ tokens: {
29
+ colors: {
30
+ [k: string]: {
31
+ value: string;
32
+ };
33
+ };
34
+ radii: {
35
+ [k: string]: {
36
+ value: string;
37
+ };
38
+ };
39
+ spacing: {
40
+ [k: string]: {
41
+ value: string;
42
+ };
43
+ };
44
+ };
45
+ };
46
+ };
@@ -0,0 +1,13 @@
1
+ import { type BambooVitePluginOptions } from '@bamboocss/vite';
2
+ import type { Plugin } from 'vite';
3
+ export interface XplatBambooOptions extends BambooVitePluginOptions {
4
+ /** NativeScript consumes CSS assets in its own generateBundle hook. */
5
+ native?: boolean;
6
+ }
7
+ /**
8
+ * Create Bamboo's Vite plugins for an Octane xplat app.
9
+ *
10
+ * Pass `cwd` and `configPath` when Bamboo's source/config root differs from
11
+ * Vite's app root, as it does in the shared harness.
12
+ */
13
+ export declare function xplatBamboo({ native, ...options }?: XplatBambooOptions): Plugin<any>[];