@octane-xplat/bamboo 0.0.0-nightly.g14544fe
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 +21 -0
- package/README.md +55 -0
- package/package.json +63 -0
- package/src/config.ts +129 -0
- package/src/platform-output.ts +212 -0
- package/src/vite.ts +118 -0
- package/types/generated/config.d.ts +58 -0
- package/types/generated/platform-output.d.ts +3 -0
- package/types/generated/vite.d.ts +13 -0
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,55 @@
|
|
|
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
|
+
Platform conditions use the same build-time compiler as ordinary CSS. Add
|
|
41
|
+
`xplatCss('web')` from `@octane-xplat/cli/vite` to web plugins; native presets
|
|
42
|
+
include it. Keep the portable utility subset unless you explicitly extend it.
|
|
43
|
+
SSR generation with platform conditions is currently unsupported.
|
|
44
|
+
|
|
45
|
+
```ts
|
|
46
|
+
import { css } from './styled-system/css'
|
|
47
|
+
|
|
48
|
+
const card = css({
|
|
49
|
+
padding: '4',
|
|
50
|
+
_web: { color: 'primary' },
|
|
51
|
+
_mobile: { color: 'text' },
|
|
52
|
+
})
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
Guide: [Styling screens](../../docs/app/styling.md).
|
package/package.json
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@octane-xplat/bamboo",
|
|
3
|
+
"version": "0.0.0-nightly.g14544fe",
|
|
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
|
+
"magic-string": "0.30.21",
|
|
48
|
+
"@ampproject/remapping": "2.3.0"
|
|
49
|
+
},
|
|
50
|
+
"devDependencies": {
|
|
51
|
+
"typescript": "5.9.3",
|
|
52
|
+
"@bamboocss/dev": "1.56.2",
|
|
53
|
+
"@octane-xplat/cli": "0.0.0-nightly.g14544fe"
|
|
54
|
+
},
|
|
55
|
+
"peerDependencies": {
|
|
56
|
+
"vite": ">=5"
|
|
57
|
+
},
|
|
58
|
+
"scripts": {
|
|
59
|
+
"test:packed": "node tests/packed-consumer.mjs",
|
|
60
|
+
"typegen": "tsc -p tsconfig.types.json",
|
|
61
|
+
"test": "node --test tests/platform.test.mjs"
|
|
62
|
+
}
|
|
63
|
+
}
|
package/src/config.ts
ADDED
|
@@ -0,0 +1,129 @@
|
|
|
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
|
+
// Compile through the framework CSS pipeline, rather than adding runtime
|
|
79
|
+
// ancestor selectors or selector specificity. These names also generate types.
|
|
80
|
+
const platformConditions = {
|
|
81
|
+
web: '@platform web',
|
|
82
|
+
mobile: '@platform mobile',
|
|
83
|
+
native: '@platform native',
|
|
84
|
+
ios: '@platform ios',
|
|
85
|
+
android: '@platform android',
|
|
86
|
+
visionos: '@platform visionos',
|
|
87
|
+
macos: '@platform macos',
|
|
88
|
+
windows: '@platform windows',
|
|
89
|
+
linux: '@platform linux',
|
|
90
|
+
gtk: '@platform gtk',
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Utilities and tokens selected for the CSS subset shared by NativeScript and
|
|
95
|
+
* browsers. This intentionally omits Bamboo's full browser-oriented preset;
|
|
96
|
+
* apps can extend it when they have checked a property on their targets.
|
|
97
|
+
*/
|
|
98
|
+
export const xplatPortablePreset: Preset = {
|
|
99
|
+
name: '@octane-xplat/bamboo/portable',
|
|
100
|
+
conditions: platformConditions,
|
|
101
|
+
utilities: portableUtilities,
|
|
102
|
+
theme: portableTheme,
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* Bamboo defaults for apps using the shared Octane xplat stylesheet.
|
|
107
|
+
*
|
|
108
|
+
* Pass this object to `defineConfig` from `@bamboocss/dev`, then add the app's
|
|
109
|
+
* `include` and `outdir`. The shared UI stylesheet declares the matching layer
|
|
110
|
+
* order before `virtual:bamboo.css` is imported.
|
|
111
|
+
*/
|
|
112
|
+
export const xplatBambooConfig = {
|
|
113
|
+
preflight: false,
|
|
114
|
+
conditions: platformConditions,
|
|
115
|
+
cssVarRoot: ':root, .ns-root',
|
|
116
|
+
layers: {
|
|
117
|
+
reset: 'xplat.reset',
|
|
118
|
+
base: 'xplat.base',
|
|
119
|
+
tokens: 'xplat.tokens',
|
|
120
|
+
recipes: 'xplat.recipes',
|
|
121
|
+
utilities: 'xplat.utilities',
|
|
122
|
+
},
|
|
123
|
+
presets: [],
|
|
124
|
+
utilities: portableUtilities,
|
|
125
|
+
theme: portableTheme,
|
|
126
|
+
} satisfies Pick<
|
|
127
|
+
UserConfig,
|
|
128
|
+
'conditions' | 'preflight' | 'cssVarRoot' | 'layers' | 'presets' | 'utilities' | 'theme'
|
|
129
|
+
>
|
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto'
|
|
2
|
+
import { posix } from 'node:path'
|
|
3
|
+
import MagicString from 'magic-string'
|
|
4
|
+
import remapping from '@ampproject/remapping'
|
|
5
|
+
import type { Plugin } from 'vite'
|
|
6
|
+
|
|
7
|
+
interface PlatformCssApi {
|
|
8
|
+
defer(id: string): void
|
|
9
|
+
filter(css: string, from?: string): string
|
|
10
|
+
project(css: string, from: string, previousMap?: string): { css: string; map?: string }
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/** Filter only after Bamboo's validation and restore content-addressed asset names. */
|
|
14
|
+
export function platformOutput(): Plugin {
|
|
15
|
+
let compiler: PlatformCssApi | undefined
|
|
16
|
+
let ssr = false
|
|
17
|
+
const adapted = new WeakSet<Plugin>()
|
|
18
|
+
return {
|
|
19
|
+
name: 'xplat-bamboo:platform-output',
|
|
20
|
+
enforce: 'post',
|
|
21
|
+
configResolved(config) {
|
|
22
|
+
ssr = Boolean(config.build.ssr)
|
|
23
|
+
compiler = config.plugins.find((plugin) => plugin.name === 'xplat-platform-css')?.api
|
|
24
|
+
if (config.command === 'build') {
|
|
25
|
+
compiler?.defer('virtual:bamboo.css')
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
transform: {
|
|
29
|
+
order: 'pre',
|
|
30
|
+
handler(code, id) {
|
|
31
|
+
if (!id.split('?')[0].endsWith('virtual:bamboo.css') || !code.includes('@platform')) {
|
|
32
|
+
return
|
|
33
|
+
}
|
|
34
|
+
if (!compiler) {
|
|
35
|
+
this.error(
|
|
36
|
+
'@octane-xplat/bamboo: platform conditions require xplatCss(target) from @octane-xplat/cli/vite',
|
|
37
|
+
)
|
|
38
|
+
}
|
|
39
|
+
if (ssr || this.environment?.config.build.ssr) {
|
|
40
|
+
this.error(
|
|
41
|
+
'@octane-xplat/bamboo: platform conditions currently require a single renderer build; SSR generation is not supported',
|
|
42
|
+
)
|
|
43
|
+
}
|
|
44
|
+
},
|
|
45
|
+
},
|
|
46
|
+
options: {
|
|
47
|
+
order: 'post',
|
|
48
|
+
handler(input) {
|
|
49
|
+
const outputs = (
|
|
50
|
+
input as typeof input & { output?: { plugins?: Plugin[] } | { plugins?: Plugin[] }[] }
|
|
51
|
+
).output
|
|
52
|
+
for (const output of Array.isArray(outputs) ? outputs : outputs ? [outputs] : []) {
|
|
53
|
+
for (const plugin of (output.plugins ?? []).flat(Infinity) as Plugin[]) {
|
|
54
|
+
if (!plugin?.name?.startsWith('bamboocss:output-finalizer:') || adapted.has(plugin)) {
|
|
55
|
+
continue
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const hook = plugin.generateBundle
|
|
59
|
+
const handler = typeof hook === 'function' ? hook : hook?.handler
|
|
60
|
+
if (!handler) {
|
|
61
|
+
throw new Error(
|
|
62
|
+
'@octane-xplat/bamboo: output finalizer has no generateBundle handler',
|
|
63
|
+
)
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
plugin.generateBundle = {
|
|
67
|
+
...(typeof hook === 'object' ? hook : {}),
|
|
68
|
+
async handler(options, bundle, isWrite) {
|
|
69
|
+
await handler.call(this, options, bundle, isWrite)
|
|
70
|
+
if (!compiler) {
|
|
71
|
+
return
|
|
72
|
+
}
|
|
73
|
+
const renamed = new Map<string, string>()
|
|
74
|
+
for (const [key, asset] of Object.entries(bundle)) {
|
|
75
|
+
if (asset.type !== 'asset' || !asset.fileName.endsWith('.css')) {
|
|
76
|
+
continue
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
const source =
|
|
80
|
+
typeof asset.source === 'string'
|
|
81
|
+
? asset.source
|
|
82
|
+
: new TextDecoder().decode(asset.source)
|
|
83
|
+
|
|
84
|
+
const mapKey = `${asset.fileName}.map`
|
|
85
|
+
const mapAsset = bundle[mapKey]
|
|
86
|
+
const previousMap =
|
|
87
|
+
mapAsset?.type === 'asset' ? String(mapAsset.source) : undefined
|
|
88
|
+
|
|
89
|
+
if (!source.includes('@platform')) {
|
|
90
|
+
continue
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
const projected = compiler.project(source, asset.fileName, previousMap)
|
|
94
|
+
let filtered = projected.css
|
|
95
|
+
if (filtered === source) {
|
|
96
|
+
continue
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
const hash = createHash('sha256').update(filtered).digest('hex').slice(0, 16)
|
|
100
|
+
const next = asset.fileName.replace(/\.css$/, `.platform-${hash}.css`)
|
|
101
|
+
renamed.set(asset.fileName, next)
|
|
102
|
+
if (projected.map && previousMap) {
|
|
103
|
+
const nextMap = `${next}.map`
|
|
104
|
+
const map = JSON.parse(projected.map)
|
|
105
|
+
map.file = posix.basename(next)
|
|
106
|
+
this.emitFile({ type: 'asset', fileName: nextMap, source: JSON.stringify(map) })
|
|
107
|
+
delete bundle[mapKey]
|
|
108
|
+
filtered += `
|
|
109
|
+
/*# sourceMappingURL=${posix.basename(nextMap)} */`
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
this.emitFile({ type: 'asset', fileName: next, source: filtered })
|
|
113
|
+
delete bundle[key]
|
|
114
|
+
}
|
|
115
|
+
for (const file of Object.values(bundle)) {
|
|
116
|
+
const replace = (text: string) => {
|
|
117
|
+
for (const [old, next] of renamed) {
|
|
118
|
+
text = text.split(old).join(next)
|
|
119
|
+
const directory = posix.dirname(file.fileName)
|
|
120
|
+
text = text
|
|
121
|
+
.split(posix.relative(directory, old))
|
|
122
|
+
.join(posix.relative(directory, next))
|
|
123
|
+
}
|
|
124
|
+
return text
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
if (file.type === 'chunk') {
|
|
128
|
+
const nextCode = replace(file.code)
|
|
129
|
+
if (nextCode !== file.code) {
|
|
130
|
+
const magic = new MagicString(file.code)
|
|
131
|
+
const replacements = new Map(renamed)
|
|
132
|
+
for (const [old, next] of renamed) {
|
|
133
|
+
replacements.set(
|
|
134
|
+
posix.relative(posix.dirname(file.fileName), old),
|
|
135
|
+
posix.relative(posix.dirname(file.fileName), next),
|
|
136
|
+
)
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
// Scan the original code once so overlapping full/relative names
|
|
140
|
+
// cannot apply two edits to the same source-map span.
|
|
141
|
+
for (let index = 0; index < file.code.length; index++) {
|
|
142
|
+
const found = [...replacements].find(([old]) =>
|
|
143
|
+
file.code.startsWith(old, index),
|
|
144
|
+
)
|
|
145
|
+
|
|
146
|
+
if (!found) {
|
|
147
|
+
continue
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
magic.overwrite(index, index + found[0].length, found[1])
|
|
151
|
+
index += found[0].length - 1
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
file.code = magic.toString()
|
|
155
|
+
if (file.map) {
|
|
156
|
+
const combined = remapping(
|
|
157
|
+
[
|
|
158
|
+
magic.generateMap({ source: file.fileName, hires: 'boundary' }),
|
|
159
|
+
file.map,
|
|
160
|
+
] as never,
|
|
161
|
+
() => null,
|
|
162
|
+
)
|
|
163
|
+
|
|
164
|
+
const encoded = combined.toString()
|
|
165
|
+
file.map = Object.assign(combined, {
|
|
166
|
+
toUrl: () =>
|
|
167
|
+
`data:application/json;charset=utf-8;base64,${Buffer.from(encoded).toString('base64')}`,
|
|
168
|
+
}) as typeof file.map
|
|
169
|
+
|
|
170
|
+
const mapFile = bundle[`${file.fileName}.map`]
|
|
171
|
+
if (mapFile?.type === 'asset') {
|
|
172
|
+
mapFile.source = encoded
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
if (file.code.includes('//# sourceMappingURL=data:')) {
|
|
176
|
+
file.code =
|
|
177
|
+
file.code.replace(
|
|
178
|
+
/\n?\/\/# sourceMappingURL=data:application\/json[^\n]*$/,
|
|
179
|
+
'',
|
|
180
|
+
) +
|
|
181
|
+
`
|
|
182
|
+
//# sourceMappingURL=${file.map.toUrl()}`
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
const refs = file as typeof file & { referencedFiles?: string[] }
|
|
188
|
+
if (refs.referencedFiles) {
|
|
189
|
+
refs.referencedFiles = refs.referencedFiles.map(replace)
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
const metadata = (
|
|
193
|
+
file as typeof file & { viteMetadata?: { importedCss?: Set<string> } }
|
|
194
|
+
).viteMetadata
|
|
195
|
+
|
|
196
|
+
if (metadata?.importedCss) {
|
|
197
|
+
metadata.importedCss = new Set([...metadata.importedCss].map(replace))
|
|
198
|
+
}
|
|
199
|
+
} else if (typeof file.source === 'string') {
|
|
200
|
+
file.source = replace(file.source)
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
},
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
adapted.add(plugin)
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
},
|
|
210
|
+
},
|
|
211
|
+
}
|
|
212
|
+
}
|
package/src/vite.ts
ADDED
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import { bamboocss, type BambooVitePluginOptions } from '@bamboocss/vite'
|
|
2
|
+
import type { Plugin } from 'vite'
|
|
3
|
+
import { platformOutput } from './platform-output.ts'
|
|
4
|
+
|
|
5
|
+
function runBeforeNativeCss(plugin: Plugin | undefined, anchor: string) {
|
|
6
|
+
const hook = plugin?.generateBundle
|
|
7
|
+
if (plugin && typeof hook === 'function') {
|
|
8
|
+
plugin.generateBundle = { order: 'pre', handler: hook }
|
|
9
|
+
} else if (hook && typeof hook === 'object' && typeof hook.handler === 'function') {
|
|
10
|
+
hook.order = 'pre'
|
|
11
|
+
} else {
|
|
12
|
+
throw new Error(
|
|
13
|
+
`@octane-xplat/bamboo: native CSS adaptation requires ${anchor} with a generateBundle handler`,
|
|
14
|
+
)
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export interface XplatBambooOptions extends BambooVitePluginOptions {
|
|
19
|
+
/** NativeScript consumes CSS assets in its own generateBundle hook. */
|
|
20
|
+
native?: boolean
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Create Bamboo's Vite plugins for an Octane xplat app.
|
|
25
|
+
*
|
|
26
|
+
* Pass `cwd` and `configPath` when Bamboo's source/config root differs from
|
|
27
|
+
* Vite's app root, as it does in the shared harness.
|
|
28
|
+
*/
|
|
29
|
+
export function xplatBamboo({ native = false, ...options }: XplatBambooOptions = {}) {
|
|
30
|
+
const plugins = bamboocss(options)
|
|
31
|
+
|
|
32
|
+
if (native) {
|
|
33
|
+
// Let Bamboo prune and validate the emitted asset before NativeScript's
|
|
34
|
+
// main-entry hook serializes it into the native bootstrap and removes it.
|
|
35
|
+
const cssPlugin = plugins.find((plugin) => plugin.name === 'bamboocss:css')
|
|
36
|
+
runBeforeNativeCss(cssPlugin, 'bamboocss:css')
|
|
37
|
+
|
|
38
|
+
let isBuild = false
|
|
39
|
+
plugins.push({
|
|
40
|
+
name: 'xplat-bamboo:nativescript-entry-graph',
|
|
41
|
+
enforce: 'post',
|
|
42
|
+
configResolved(config) {
|
|
43
|
+
isBuild = config.command === 'build'
|
|
44
|
+
},
|
|
45
|
+
buildEnd(error) {
|
|
46
|
+
if (!isBuild || error) {
|
|
47
|
+
return
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// Inspect the graph, including cached modules in watch builds. A
|
|
51
|
+
// custom entry that already imports the sheet needs no injection.
|
|
52
|
+
if (![...this.getModuleIds()].some((id) => id.split('?')[0] === '\0virtual:bamboo.css')) {
|
|
53
|
+
this.error(
|
|
54
|
+
'@octane-xplat/bamboo: native entry graph is missing virtual:bamboo.css; expected virtual:entry-with-polyfills or an explicit stylesheet import',
|
|
55
|
+
)
|
|
56
|
+
}
|
|
57
|
+
},
|
|
58
|
+
transform(code, id) {
|
|
59
|
+
// @nativescript/vite builds from a generated entry
|
|
60
|
+
// (`virtual:entry-with-polyfills`). Under HMR that entry boots
|
|
61
|
+
// the app over HTTP instead of statically importing the app's
|
|
62
|
+
// main module, so `import 'virtual:bamboo.css'` there never
|
|
63
|
+
// enters the bundle's module graph — while class values still
|
|
64
|
+
// compile, tripping bamboocss's entry-graph check at buildEnd.
|
|
65
|
+
// Import the stylesheet from the generated entry itself so it
|
|
66
|
+
// is in the graph in every mode; the emitted asset then flows
|
|
67
|
+
// through the same generateBundle path as every other .css.
|
|
68
|
+
if (id !== '\0virtual:entry-with-polyfills' || code.includes('virtual:bamboo.css')) {
|
|
69
|
+
return
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
return { code: `${code}\nimport 'virtual:bamboo.css';\n`, map: null }
|
|
73
|
+
},
|
|
74
|
+
})
|
|
75
|
+
|
|
76
|
+
plugins.push({
|
|
77
|
+
name: 'xplat-bamboo:nativescript-output',
|
|
78
|
+
enforce: 'post',
|
|
79
|
+
options: {
|
|
80
|
+
order: 'post',
|
|
81
|
+
handler(inputOptions) {
|
|
82
|
+
const options = inputOptions as typeof inputOptions & {
|
|
83
|
+
output?: { plugins?: Plugin[] } | Array<{ plugins?: Plugin[] }>
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
const outputs = Array.isArray(options.output)
|
|
87
|
+
? options.output
|
|
88
|
+
: options.output
|
|
89
|
+
? [options.output]
|
|
90
|
+
: []
|
|
91
|
+
|
|
92
|
+
// Upstream installs one finalizer per configured output. With no
|
|
93
|
+
// output configured its options hook deliberately installs none.
|
|
94
|
+
for (const output of outputs) {
|
|
95
|
+
const finalizers = (output.plugins ?? [])
|
|
96
|
+
.flat(Infinity)
|
|
97
|
+
.filter((plugin): plugin is Plugin =>
|
|
98
|
+
Boolean(plugin && plugin.name?.startsWith('bamboocss:output-finalizer:')),
|
|
99
|
+
)
|
|
100
|
+
|
|
101
|
+
if (!finalizers.length) {
|
|
102
|
+
throw new Error(
|
|
103
|
+
'@octane-xplat/bamboo: native CSS adaptation requires a bamboocss:output-finalizer:* plugin for each configured output',
|
|
104
|
+
)
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
for (const finalizer of finalizers) {
|
|
108
|
+
runBeforeNativeCss(finalizer, finalizer.name)
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
},
|
|
112
|
+
},
|
|
113
|
+
})
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
plugins.push(platformOutput())
|
|
117
|
+
return plugins
|
|
118
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
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
|
+
conditions: {
|
|
18
|
+
web: string;
|
|
19
|
+
mobile: string;
|
|
20
|
+
native: string;
|
|
21
|
+
ios: string;
|
|
22
|
+
android: string;
|
|
23
|
+
visionos: string;
|
|
24
|
+
macos: string;
|
|
25
|
+
windows: string;
|
|
26
|
+
linux: string;
|
|
27
|
+
gtk: string;
|
|
28
|
+
};
|
|
29
|
+
cssVarRoot: string;
|
|
30
|
+
layers: {
|
|
31
|
+
reset: string;
|
|
32
|
+
base: string;
|
|
33
|
+
tokens: string;
|
|
34
|
+
recipes: string;
|
|
35
|
+
utilities: string;
|
|
36
|
+
};
|
|
37
|
+
presets: never[];
|
|
38
|
+
utilities: UtilityConfig;
|
|
39
|
+
theme: {
|
|
40
|
+
tokens: {
|
|
41
|
+
colors: {
|
|
42
|
+
[k: string]: {
|
|
43
|
+
value: string;
|
|
44
|
+
};
|
|
45
|
+
};
|
|
46
|
+
radii: {
|
|
47
|
+
[k: string]: {
|
|
48
|
+
value: string;
|
|
49
|
+
};
|
|
50
|
+
};
|
|
51
|
+
spacing: {
|
|
52
|
+
[k: string]: {
|
|
53
|
+
value: string;
|
|
54
|
+
};
|
|
55
|
+
};
|
|
56
|
+
};
|
|
57
|
+
};
|
|
58
|
+
};
|
|
@@ -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>[];
|