From db8985d9b1835860e03bccb377515684803a3c9e Mon Sep 17 00:00:00 2001 From: Matthew Phillips Date: Thu, 29 Jun 2023 13:20:51 -0400 Subject: [PATCH 01/10] Rename to transition:animate --- internal/node.go | 10 ++++++---- internal/printer/print-to-js.go | 14 ++++++++++++++ internal/printer/printer.go | 10 +++++++++- internal/transform/transform.go | 13 +++++++++++++ 4 files changed, 42 insertions(+), 5 deletions(-) diff --git a/internal/node.go b/internal/node.go index 265bbfe1b..11973b81b 100644 --- a/internal/node.go +++ b/internal/node.go @@ -79,10 +79,12 @@ type HydratedComponentMetadata struct { // Similarly, "math" is short for "http://www.w3.org/1998/Math/MathML", and // "svg" is short for "http://www.w3.org/2000/svg". type Node struct { - Fragment bool - CustomElement bool - Component bool - Expression bool + Fragment bool + CustomElement bool + Component bool + Expression bool + Transition bool + TransitionScope string Parent, FirstChild, LastChild, PrevSibling, NextSibling *Node diff --git a/internal/printer/print-to-js.go b/internal/printer/print-to-js.go index 68d2c6038..d5d85dc8c 100644 --- a/internal/printer/print-to-js.go +++ b/internal/printer/print-to-js.go @@ -110,6 +110,10 @@ func emptyTextNodeWithoutSiblings(n *Node) bool { func render1(p *printer, n *Node, opts RenderOptions) { depth := opts.depth + if n.Transition { + p.needsTransitionCSS = true + } + // Root of the document, print all children if n.Type == DocumentNode { p.printInternalImports(p.opts.InternalURL, &opts) @@ -692,6 +696,16 @@ func render1(p *printer, n *Node, opts RenderOptions) { } p.printTemplateLiteralClose() default: + if transform.HasAttr(n, "transition:animate") { + transitionName := "" + if transform.HasAttr(n, "transition:name") { + transitionName = transform.GetAttr(n, "transition:name").Val + } + + val := transform.GetAttr(n, "transition:animate").Val + p.print(fmt.Sprintf(`${%s(%s, "%s", "%s", "%s")}`, RENDER_TRANSITION, RESULT, n.TransitionScope, val, transitionName)) + } + for c := n.FirstChild; c != nil; c = c.NextSibling { render1(p, c, RenderOptions{ isRoot: false, diff --git a/internal/printer/printer.go b/internal/printer/printer.go index 93001e828..c35cdd3cc 100644 --- a/internal/printer/printer.go +++ b/internal/printer/printer.go @@ -28,6 +28,7 @@ type printer struct { hasFuncPrelude bool hasInternalImports bool hasCSSImports bool + needsTransitionCSS bool } var TEMPLATE_TAG = "$$render" @@ -40,6 +41,7 @@ var UNESCAPE_HTML = "$$unescapeHTML" var RENDER_SLOT = "$$renderSlot" var MERGE_SLOTS = "$$mergeSlots" var ADD_ATTRIBUTE = "$$addAttribute" +var RENDER_TRANSITION = "$$renderTransition" var SPREAD_ATTRIBUTES = "$$spreadAttributes" var DEFINE_STYLE_VARS = "$$defineStyleVars" var DEFINE_SCRIPT_VARS = "$$defineScriptVars" @@ -116,6 +118,8 @@ func (p *printer) printInternalImports(importSpecifier string, opts *RenderOptio p.print("defineStyleVars as " + DEFINE_STYLE_VARS + ",\n ") p.addNilSourceMapping() p.print("defineScriptVars as " + DEFINE_SCRIPT_VARS + ",\n ") + p.addNilSourceMapping() + p.print("renderTransition as " + RENDER_TRANSITION + ",\n ") // Only needed if using fallback `resolvePath` as it calls `$$metadata.resolvePath` if opts.opts.ResolvePath == nil { @@ -141,6 +145,10 @@ func (p *printer) printCSSImports(cssLen int) { p.print(fmt.Sprintf("import \"%s?astro&type=style&index=%v&lang.css\";", p.opts.Filename, i)) i++ } + if p.needsTransitionCSS { + p.addNilSourceMapping() + p.print(`import "astro/components/viewtransitions.css";`) + } p.print("\n") p.hasCSSImports = true } @@ -323,7 +331,7 @@ func (p *printer) printAttributesToObject(n *astro.Node) { } func (p *printer) printAttribute(attr astro.Attribute, n *astro.Node) { - if attr.Key == "define:vars" || attr.Key == "set:text" || attr.Key == "set:html" || attr.Key == "is:raw" { + if attr.Key == "define:vars" || attr.Key == "set:text" || attr.Key == "set:html" || attr.Key == "is:raw" || attr.Key == "transition:animate" || attr.Key == "transition:name" { return } diff --git a/internal/transform/transform.go b/internal/transform/transform.go index c96661a1a..ade70d389 100644 --- a/internal/transform/transform.go +++ b/internal/transform/transform.go @@ -13,6 +13,8 @@ import ( a "golang.org/x/net/html/atom" ) +const ANIMATE_TRANSITION = "transition:animate" + type TransformOptions struct { Scope string Filename string @@ -31,12 +33,23 @@ func Transform(doc *astro.Node, opts TransformOptions, h *handler.Handler) *astr shouldScope := len(doc.Styles) > 0 && ScopeStyle(doc.Styles, opts) definedVars := GetDefineVars(doc.Styles) didAddDefinedVars := false + i := 0 walk(doc, func(n *astro.Node) { + i++ ExtractScript(doc, n, &opts, h) AddComponentProps(doc, n, &opts) if shouldScope { ScopeElement(n, opts) } + if HasAttr(n, ANIMATE_TRANSITION) { + doc.Transition = true + n.TransitionScope = astro.HashString(fmt.Sprintf("%s-%v", opts.Scope, i)) + n.Attr = append(n.Attr, astro.Attribute{ + Key: "data-astro-transition-scope", + Val: n.TransitionScope, + Type: astro.QuotedAttribute, + }) + } if len(definedVars) > 0 { didAdd := AddDefineVars(n, definedVars) if !didAddDefinedVars { From ef8304f0fea2fbc75434be3d4c267bd808d3c1c7 Mon Sep 17 00:00:00 2001 From: Matthew Phillips Date: Thu, 29 Jun 2023 16:57:03 -0400 Subject: [PATCH 02/10] Pass propagation --- internal/printer/printer.go | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/internal/printer/printer.go b/internal/printer/printer.go index c35cdd3cc..91410cea2 100644 --- a/internal/printer/printer.go +++ b/internal/printer/printer.go @@ -258,15 +258,19 @@ func (p *printer) printFuncPrelude(opts transform.TransformOptions) { p.hasFuncPrelude = true } -func (p *printer) printFuncSuffix(opts transform.TransformOptions) { +func (p *printer) printFuncSuffix(opts transform.TransformOptions, n *astro.Node) { componentName := getComponentName(opts.Filename) p.addNilSourceMapping() + filenameArg := "undefined" + propagationArg := "undefined" if len(opts.Filename) > 0 { escapedFilename := strings.ReplaceAll(opts.Filename, "'", "\\'") - p.println(fmt.Sprintf("}, '%s');", escapedFilename)) - } else { - p.println("});") + filenameArg = fmt.Sprintf("'%s'", escapedFilename) + } + if n.Transition { + propagationArg = "'self'" } + p.println(fmt.Sprintf("}, %s, %s);", filenameArg, propagationArg)) p.println(fmt.Sprintf("export default %s;", componentName)) } From 76e6c377237f72b74fb7bb35b72c43b36696ce1e Mon Sep 17 00:00:00 2001 From: Matthew Phillips Date: Thu, 29 Jun 2023 16:57:39 -0400 Subject: [PATCH 03/10] Pass in the node --- internal/printer/print-to-js.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/printer/print-to-js.go b/internal/printer/print-to-js.go index d5d85dc8c..52686273a 100644 --- a/internal/printer/print-to-js.go +++ b/internal/printer/print-to-js.go @@ -133,7 +133,7 @@ func render1(p *printer, n *Node, opts RenderOptions) { } p.printReturnClose() - p.printFuncSuffix(opts.opts) + p.printFuncSuffix(opts.opts, n) return } From ff5e8c07b7b7070631fb6d555f24724f90e37c47 Mon Sep 17 00:00:00 2001 From: Matthew Phillips Date: Fri, 30 Jun 2023 08:51:04 -0400 Subject: [PATCH 04/10] Move where the transition is rendered --- internal/printer/print-to-js.go | 29 +++++++++++++++++++---------- internal/transform/transform.go | 10 +++------- 2 files changed, 22 insertions(+), 17 deletions(-) diff --git a/internal/printer/print-to-js.go b/internal/printer/print-to-js.go index 52686273a..5bba92293 100644 --- a/internal/printer/print-to-js.go +++ b/internal/printer/print-to-js.go @@ -11,6 +11,7 @@ import ( "strings" . "github.com/withastro/compiler/internal" + astro "github.com/withastro/compiler/internal" "github.com/withastro/compiler/internal/handler" "github.com/withastro/compiler/internal/js_scanner" "github.com/withastro/compiler/internal/loc" @@ -433,10 +434,28 @@ func render1(p *printer, n *Node, opts RenderOptions) { } p.print(`]`) } else { + if transform.HasAttr(n, transform.TRANSITION_ANIMATE) || transform.HasAttr(n, transform.TRANSITION_NAME) { + animationName := "" + if transform.HasAttr(n, transform.TRANSITION_ANIMATE) { + animationName = transform.GetAttr(n, transform.TRANSITION_ANIMATE).Val + } + transitionName := "" + if transform.HasAttr(n, transform.TRANSITION_NAME) { + transitionName = transform.GetAttr(n, transform.TRANSITION_NAME).Val + } + + n.Attr = append(n.Attr, astro.Attribute{ + Key: "data-astro-transition-scope", + Val: fmt.Sprintf(`${%s(%s, "%s", "%s", "%s")}`, RENDER_TRANSITION, RESULT, n.TransitionScope, animationName, transitionName), + Type: astro.ExpressionAttribute, + }) + } + for _, a := range n.Attr { if transform.IsImplicitNodeMarker(a) || a.Key == "is:inline" { continue } + if a.Key == "slot" { if n.Parent.Component || n.Parent.Expression { continue @@ -696,16 +715,6 @@ func render1(p *printer, n *Node, opts RenderOptions) { } p.printTemplateLiteralClose() default: - if transform.HasAttr(n, "transition:animate") { - transitionName := "" - if transform.HasAttr(n, "transition:name") { - transitionName = transform.GetAttr(n, "transition:name").Val - } - - val := transform.GetAttr(n, "transition:animate").Val - p.print(fmt.Sprintf(`${%s(%s, "%s", "%s", "%s")}`, RENDER_TRANSITION, RESULT, n.TransitionScope, val, transitionName)) - } - for c := n.FirstChild; c != nil; c = c.NextSibling { render1(p, c, RenderOptions{ isRoot: false, diff --git a/internal/transform/transform.go b/internal/transform/transform.go index ade70d389..f1a461f9a 100644 --- a/internal/transform/transform.go +++ b/internal/transform/transform.go @@ -13,7 +13,8 @@ import ( a "golang.org/x/net/html/atom" ) -const ANIMATE_TRANSITION = "transition:animate" +const TRANSITION_ANIMATE = "transition:animate" +const TRANSITION_NAME = "transition:name" type TransformOptions struct { Scope string @@ -41,14 +42,9 @@ func Transform(doc *astro.Node, opts TransformOptions, h *handler.Handler) *astr if shouldScope { ScopeElement(n, opts) } - if HasAttr(n, ANIMATE_TRANSITION) { + if HasAttr(n, TRANSITION_ANIMATE) || HasAttr(n, TRANSITION_NAME) { doc.Transition = true n.TransitionScope = astro.HashString(fmt.Sprintf("%s-%v", opts.Scope, i)) - n.Attr = append(n.Attr, astro.Attribute{ - Key: "data-astro-transition-scope", - Val: n.TransitionScope, - Type: astro.QuotedAttribute, - }) } if len(definedVars) > 0 { didAdd := AddDefineVars(n, definedVars) From eb43a5a288fb3fad48b0d3fbbad6b4e3efd2ea77 Mon Sep 17 00:00:00 2001 From: Matthew Phillips Date: Fri, 30 Jun 2023 09:01:33 -0400 Subject: [PATCH 05/10] Don't wrap the attr --- internal/printer/print-to-js.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/printer/print-to-js.go b/internal/printer/print-to-js.go index 5bba92293..715993529 100644 --- a/internal/printer/print-to-js.go +++ b/internal/printer/print-to-js.go @@ -446,7 +446,7 @@ func render1(p *printer, n *Node, opts RenderOptions) { n.Attr = append(n.Attr, astro.Attribute{ Key: "data-astro-transition-scope", - Val: fmt.Sprintf(`${%s(%s, "%s", "%s", "%s")}`, RENDER_TRANSITION, RESULT, n.TransitionScope, animationName, transitionName), + Val: fmt.Sprintf(`%s(%s, "%s", "%s", "%s")`, RENDER_TRANSITION, RESULT, n.TransitionScope, animationName, transitionName), Type: astro.ExpressionAttribute, }) } From 26a456dbc6ea558e61437d136b600a713a56a80c Mon Sep 17 00:00:00 2001 From: Matthew Phillips Date: Mon, 17 Jul 2023 15:00:49 -0400 Subject: [PATCH 06/10] Update tests with new expected output --- internal/printer/printer_test.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/internal/printer/printer_test.go b/internal/printer/printer_test.go index f5f57243a..c722dfb34 100644 --- a/internal/printer/printer_test.go +++ b/internal/printer/printer_test.go @@ -30,6 +30,7 @@ var INTERNAL_IMPORTS = fmt.Sprintf("import {\n %s\n} from \"%s\";\n", strings.J "spreadAttributes as " + SPREAD_ATTRIBUTES, "defineStyleVars as " + DEFINE_STYLE_VARS, "defineScriptVars as " + DEFINE_SCRIPT_VARS, + "renderTransition as " + RENDER_TRANSITION, "createMetadata as " + CREATE_METADATA, }, ",\n "), "http://localhost:3000/") var PRELUDE = fmt.Sprintf(`const $$Component = %s(async ($$result, $$props, %s) => { @@ -37,7 +38,7 @@ const Astro = $$result.createAstro($$Astro, $$props, %s); Astro.self = $$Component;%s`, CREATE_COMPONENT, SLOTS, SLOTS, "\n\n") var RETURN = fmt.Sprintf("return %s%s", TEMPLATE_TAG, BACKTICK) var SUFFIX = fmt.Sprintf("%s;", BACKTICK) + ` -}); +}, undefined, undefined); export default $$Component;` var CREATE_ASTRO_CALL = "const $$Astro = $$createAstro('https://astro.build');\nconst Astro = $$Astro;" var RENDER_HEAD_RESULT = "${$$renderHead($$result)}" @@ -48,7 +49,7 @@ var NON_WHITESPACE_CHARS = []byte("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRS func suffixWithFilename(filename string) string { return fmt.Sprintf("%s;", BACKTICK) + fmt.Sprintf(` -}, '%s'); +}, '%s', undefined); export default $$Component;`, filename) } From 2fca0aa7defb80e1bb8643c04917ceabcee9a014 Mon Sep 17 00:00:00 2001 From: Matthew Phillips Date: Mon, 17 Jul 2023 15:10:07 -0400 Subject: [PATCH 07/10] Update wasm test assertion --- packages/compiler/test/basic/trailing-newline.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/compiler/test/basic/trailing-newline.ts b/packages/compiler/test/basic/trailing-newline.ts index 370a8f035..790edfe82 100644 --- a/packages/compiler/test/basic/trailing-newline.ts +++ b/packages/compiler/test/basic/trailing-newline.ts @@ -27,7 +27,7 @@ test.before(async () => { }); test('does not add trailing newline to rendered output', () => { - assert.match(result.code, `}\`;\n}, '');`, 'Does not include a trailing newline in the render function'); + assert.match(result.code, `}\`;\n}, '', undefined);`, 'Does not include a trailing newline in the render function'); }); test.run(); From 3d77119833449be346caa87fcff51a2a4f6ddf70 Mon Sep 17 00:00:00 2001 From: Matthew Phillips Date: Mon, 17 Jul 2023 15:11:09 -0400 Subject: [PATCH 08/10] Add a changeset --- .changeset/young-turkeys-wave.md | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 .changeset/young-turkeys-wave.md diff --git a/.changeset/young-turkeys-wave.md b/.changeset/young-turkeys-wave.md new file mode 100644 index 000000000..a0265df29 --- /dev/null +++ b/.changeset/young-turkeys-wave.md @@ -0,0 +1,7 @@ +--- +'@astrojs/compiler': minor +--- + +Support for view transition directives + +This adds support for `transition:animate` and `transition:name` which get passed into the new `renderTransition` runtime function. \ No newline at end of file From 7666555a99873030211c15d0fb2a5a08c33e56e6 Mon Sep 17 00:00:00 2001 From: Matthew Phillips Date: Tue, 18 Jul 2023 14:33:35 -0400 Subject: [PATCH 09/10] Make transition usage experimental to prevent backwards compat bug --- cmd/astro-wasm/astro-wasm.go | 25 +++++++++++++++---------- internal/printer/print-to-js.go | 2 +- internal/printer/printer.go | 6 ++++-- internal/printer/printer_test.go | 1 - internal/transform/transform.go | 25 +++++++++++++------------ packages/compiler/src/shared/types.ts | 1 + 6 files changed, 34 insertions(+), 26 deletions(-) diff --git a/cmd/astro-wasm/astro-wasm.go b/cmd/astro-wasm/astro-wasm.go index 3ffb91cfa..d711327a3 100644 --- a/cmd/astro-wasm/astro-wasm.go +++ b/cmd/astro-wasm/astro-wasm.go @@ -95,6 +95,10 @@ func makeTransformOptions(options js.Value) transform.TransformOptions { if jsBool(options.Get("resultScopedSlot")) { scopedSlot = true } + experimentalTransitions := false + if jsBool(options.Get("experimentalTransitions")) { + experimentalTransitions = true + } var resolvePath any = options.Get("resolvePath") var resolvePathFn func(string) string @@ -117,16 +121,17 @@ func makeTransformOptions(options js.Value) transform.TransformOptions { } return transform.TransformOptions{ - Filename: filename, - NormalizedFilename: normalizedFilename, - InternalURL: internalURL, - SourceMap: sourcemap, - AstroGlobalArgs: astroGlobalArgs, - Compact: compact, - ResolvePath: resolvePathFn, - PreprocessStyle: preprocessStyle, - ResultScopedSlot: scopedSlot, - ScopedStyleStrategy: scopedStyleStrategy, + Filename: filename, + NormalizedFilename: normalizedFilename, + InternalURL: internalURL, + SourceMap: sourcemap, + AstroGlobalArgs: astroGlobalArgs, + Compact: compact, + ResolvePath: resolvePathFn, + PreprocessStyle: preprocessStyle, + ResultScopedSlot: scopedSlot, + ScopedStyleStrategy: scopedStyleStrategy, + ExperimentalTransitions: experimentalTransitions, } } diff --git a/internal/printer/print-to-js.go b/internal/printer/print-to-js.go index 715993529..e88a68952 100644 --- a/internal/printer/print-to-js.go +++ b/internal/printer/print-to-js.go @@ -111,7 +111,7 @@ func emptyTextNodeWithoutSiblings(n *Node) bool { func render1(p *printer, n *Node, opts RenderOptions) { depth := opts.depth - if n.Transition { + if opts.opts.ExperimentalTransitions && n.Transition { p.needsTransitionCSS = true } diff --git a/internal/printer/printer.go b/internal/printer/printer.go index 91410cea2..c499bfd3f 100644 --- a/internal/printer/printer.go +++ b/internal/printer/printer.go @@ -118,8 +118,10 @@ func (p *printer) printInternalImports(importSpecifier string, opts *RenderOptio p.print("defineStyleVars as " + DEFINE_STYLE_VARS + ",\n ") p.addNilSourceMapping() p.print("defineScriptVars as " + DEFINE_SCRIPT_VARS + ",\n ") - p.addNilSourceMapping() - p.print("renderTransition as " + RENDER_TRANSITION + ",\n ") + if opts.opts.ExperimentalTransitions { + p.addNilSourceMapping() + p.print("renderTransition as " + RENDER_TRANSITION + ",\n ") + } // Only needed if using fallback `resolvePath` as it calls `$$metadata.resolvePath` if opts.opts.ResolvePath == nil { diff --git a/internal/printer/printer_test.go b/internal/printer/printer_test.go index c722dfb34..6e7d2265f 100644 --- a/internal/printer/printer_test.go +++ b/internal/printer/printer_test.go @@ -30,7 +30,6 @@ var INTERNAL_IMPORTS = fmt.Sprintf("import {\n %s\n} from \"%s\";\n", strings.J "spreadAttributes as " + SPREAD_ATTRIBUTES, "defineStyleVars as " + DEFINE_STYLE_VARS, "defineScriptVars as " + DEFINE_SCRIPT_VARS, - "renderTransition as " + RENDER_TRANSITION, "createMetadata as " + CREATE_METADATA, }, ",\n "), "http://localhost:3000/") var PRELUDE = fmt.Sprintf(`const $$Component = %s(async ($$result, $$props, %s) => { diff --git a/internal/transform/transform.go b/internal/transform/transform.go index f1a461f9a..0ed45e46e 100644 --- a/internal/transform/transform.go +++ b/internal/transform/transform.go @@ -17,17 +17,18 @@ const TRANSITION_ANIMATE = "transition:animate" const TRANSITION_NAME = "transition:name" type TransformOptions struct { - Scope string - Filename string - NormalizedFilename string - InternalURL string - SourceMap string - AstroGlobalArgs string - ScopedStyleStrategy string - Compact bool - ResultScopedSlot bool - ResolvePath func(string) string - PreprocessStyle interface{} + Scope string + Filename string + NormalizedFilename string + InternalURL string + SourceMap string + AstroGlobalArgs string + ScopedStyleStrategy string + Compact bool + ResultScopedSlot bool + ExperimentalTransitions bool + ResolvePath func(string) string + PreprocessStyle interface{} } func Transform(doc *astro.Node, opts TransformOptions, h *handler.Handler) *astro.Node { @@ -42,7 +43,7 @@ func Transform(doc *astro.Node, opts TransformOptions, h *handler.Handler) *astr if shouldScope { ScopeElement(n, opts) } - if HasAttr(n, TRANSITION_ANIMATE) || HasAttr(n, TRANSITION_NAME) { + if opts.ExperimentalTransitions && (HasAttr(n, TRANSITION_ANIMATE) || HasAttr(n, TRANSITION_NAME)) { doc.Transition = true n.TransitionScope = astro.HashString(fmt.Sprintf("%s-%v", opts.Scope, i)) } diff --git a/packages/compiler/src/shared/types.ts b/packages/compiler/src/shared/types.ts index f8534c0a1..6935a3aa1 100644 --- a/packages/compiler/src/shared/types.ts +++ b/packages/compiler/src/shared/types.ts @@ -53,6 +53,7 @@ export interface TransformOptions { * @deprecated "as" has been removed and no longer has any effect! */ as?: 'document' | 'fragment'; + experimentalTransitions?: boolean; resolvePath?: (specifier: string) => Promise; preprocessStyle?: (content: string, attrs: Record) => null | Promise; } From 49eea2614e69331eb4b6aa4164b3c394a28d1560 Mon Sep 17 00:00:00 2001 From: Matthew Phillips Date: Wed, 19 Jul 2023 09:09:59 -0400 Subject: [PATCH 10/10] Add the TransitionsAnimationURL option --- cmd/astro-wasm/astro-wasm.go | 5 +++++ internal/printer/printer.go | 2 +- internal/transform/transform.go | 1 + packages/compiler/src/shared/types.ts | 1 + 4 files changed, 8 insertions(+), 1 deletion(-) diff --git a/cmd/astro-wasm/astro-wasm.go b/cmd/astro-wasm/astro-wasm.go index d711327a3..b400e9eb7 100644 --- a/cmd/astro-wasm/astro-wasm.go +++ b/cmd/astro-wasm/astro-wasm.go @@ -99,6 +99,10 @@ func makeTransformOptions(options js.Value) transform.TransformOptions { if jsBool(options.Get("experimentalTransitions")) { experimentalTransitions = true } + transitionsAnimationURL := jsString(options.Get("transitionsAnimationURL")) + if transitionsAnimationURL == "" { + transitionsAnimationURL = "astro/components/viewtransitions.css" + } var resolvePath any = options.Get("resolvePath") var resolvePathFn func(string) string @@ -132,6 +136,7 @@ func makeTransformOptions(options js.Value) transform.TransformOptions { ResultScopedSlot: scopedSlot, ScopedStyleStrategy: scopedStyleStrategy, ExperimentalTransitions: experimentalTransitions, + TransitionsAnimationURL: transitionsAnimationURL, } } diff --git a/internal/printer/printer.go b/internal/printer/printer.go index c499bfd3f..25560b82a 100644 --- a/internal/printer/printer.go +++ b/internal/printer/printer.go @@ -149,7 +149,7 @@ func (p *printer) printCSSImports(cssLen int) { } if p.needsTransitionCSS { p.addNilSourceMapping() - p.print(`import "astro/components/viewtransitions.css";`) + p.print(fmt.Sprintf(`import "%s";`, p.opts.TransitionsAnimationURL)) } p.print("\n") p.hasCSSImports = true diff --git a/internal/transform/transform.go b/internal/transform/transform.go index 0ed45e46e..9a3d102b6 100644 --- a/internal/transform/transform.go +++ b/internal/transform/transform.go @@ -27,6 +27,7 @@ type TransformOptions struct { Compact bool ResultScopedSlot bool ExperimentalTransitions bool + TransitionsAnimationURL string ResolvePath func(string) string PreprocessStyle interface{} } diff --git a/packages/compiler/src/shared/types.ts b/packages/compiler/src/shared/types.ts index 6935a3aa1..61f663a51 100644 --- a/packages/compiler/src/shared/types.ts +++ b/packages/compiler/src/shared/types.ts @@ -54,6 +54,7 @@ export interface TransformOptions { */ as?: 'document' | 'fragment'; experimentalTransitions?: boolean; + transitionsAnimationURL?: string; resolvePath?: (specifier: string) => Promise; preprocessStyle?: (content: string, attrs: Record) => null | Promise; }