scriptloader for themeseventeen

This commit is contained in:
xing 2023-07-12 22:43:59 +08:00
parent b247b8640d
commit 25bf1dd1f7
5 changed files with 235 additions and 142 deletions

View File

@ -14,6 +14,7 @@ import (
"github.com/fthvgb1/wp-go/app/plugins"
"github.com/fthvgb1/wp-go/app/plugins/wphandle"
"github.com/fthvgb1/wp-go/app/theme"
"github.com/fthvgb1/wp-go/app/theme/wp/scriptloader"
"github.com/fthvgb1/wp-go/app/wpconfig"
"github.com/fthvgb1/wp-go/model"
"log"
@ -43,6 +44,7 @@ func init() {
if err != nil {
panic(err)
}
scriptloader.InitDefaultScriptSetting()
cache.InitActionsCommonCache()
plugins.InitDigestCache()
theme.InitTheme()
@ -116,6 +118,7 @@ func reloads() {
logs.IfError(err, "获取网站设置WpOption失败")
err = wpconfig.InitTerms()
logs.IfError(err, "获取WpTerms表失败")
scriptloader.InitDefaultScriptSetting()
wphandle.LoadPlugins()
reload.Reload()
flushCache()

View File

@ -4,14 +4,29 @@ import (
"fmt"
"github.com/fthvgb1/wp-go/app/pkg/constraints"
"github.com/fthvgb1/wp-go/app/theme/wp"
"github.com/fthvgb1/wp-go/app/theme/wp/scriptloader"
"github.com/fthvgb1/wp-go/app/wpconfig"
)
func pushScripts(h *wp.Handle) {
wp.AddStaticLocalize("twentyseventeen-skip-link-focus-fix", "twentyseventeenScreenReaderText", map[string]any{
scriptloader.EnqueueStyle("twentyseventeen-style", scriptloader.GetStylesheetUri(), nil, "20230328", "")
scriptloader.EnqueueStyles("twentyseventeen-block-style", "/assets/css/blocks.css", []string{"twentyseventeen-style"}, "20220912", "")
if "dark" == wpconfig.GetThemeModsVal(ThemeName, "colorscheme", "light") {
scriptloader.EnqueueStyles("twentyseventeen-colors-dark", "/assets/css/colors-dark.css",
[]string{"twentyseventeen-style"}, "20191025", "")
}
scriptloader.AddData("twentyseventeen-ie8", "conditional", "lt IE 9")
scriptloader.EnqueueScripts("html5", "/assets/js/html5.js", nil, "20161020", false)
scriptloader.AddData("html5", "conditional", "lt IE 9")
scriptloader.EnqueueScripts("twentyseventeen-skip-link-focus-fix", "/assets/js/skip-link-focus-fix.js", nil, "20161114", true)
scriptloader.AddStaticLocalize("twentyseventeen-skip-link-focus-fix", "twentyseventeenScreenReaderText", map[string]any{
"quote": `<svg class="icon icon-quote-right" aria-hidden="true" role="img"> <use href="#icon-quote-right" xlink:href="#icon-quote-right"></use> </svg>`,
})
wp.AddStaticLocalize("wp-custom-header", "_wpCustomHeaderSettings", map[string]any{
scriptloader.AddStaticLocalize("wp-custom-header", "_wpCustomHeaderSettings", map[string]any{
"mimeType": `video/mp4`,
"posterUrl": `/wp-content/uploads/2023/01/cropped-wallhaven-9dm7dd-1.png`,
"videoUrl": `/wp-content/uploads/2023/06/BloodMoon_GettyRM_495644264_1080_HD_ZH-CN.mp4`,

View File

@ -1,17 +1,16 @@
package wp
package scriptloader
import (
"encoding/json"
"github.com/fthvgb1/wp-go/app/pkg/config"
"github.com/fthvgb1/wp-go/app/pkg/logs"
"github.com/fthvgb1/wp-go/helper/maps"
"github.com/fthvgb1/wp-go/helper/number"
str "github.com/fthvgb1/wp-go/helper/strings"
"github.com/fthvgb1/wp-go/safety"
"os"
"path/filepath"
"regexp"
"strings"
"time"
)
func defaultScripts(m *safety.Map[string, *Script], suffix string) {
@ -241,13 +240,13 @@ func defaultScripts(m *safety.Map[string, *Script], suffix string) {
m.Store("wp-wordcount", NewScript("wp-wordcount", "/wp-includes/js/dist/wordcount"+suffix+".js", []string{"wp-polyfill"}, "feb9569307aec24292f2", 1))
}
func defaultLocalize(h *Handle) {
AddDynamicLocalize(h, "utils", "userSettings", map[string]any{
func defaultLocalize() {
/*AddDynamicLocalize(h, "utils", "userSettings", map[string]any{
"url": h.C.Request.RequestURI,
"uid": "0",
"time": number.IntToString(time.Now().Unix()),
"secure": h.IsHttps(),
})
})*/
AddStaticLocalize("wp-ajax-response", "wpAjax", map[string]any{
"noPerm": `抱歉,您不能这么做。`,
@ -367,121 +366,121 @@ func defaultTranslate() {
}
func defaultAddData() {
addData("json2", "conditional", `lt IE 8`)
addData("wp-embed-template-ie", "conditional", `lte IE 8`)
addData("wp-block-library-theme", "path", `wp-includes/css/dist/block-library/theme.min.css`)
addData("wp-block-editor", "path", `/wp-includes/css/dist/block-editor/style.min.css`)
addData("wp-block-library", "path", `/wp-includes/css/dist/block-library/style.min.css`)
addData("wp-block-directory", "path", `/wp-includes/css/dist/block-directory/style.min.css`)
addData("wp-components", "path", `/wp-includes/css/dist/components/style.min.css`)
addData("wp-edit-post", "path", `/wp-includes/css/dist/edit-post/style.min.css`)
addData("wp-editor", "path", `/wp-includes/css/dist/editor/style.min.css`)
addData("wp-format-library", "path", `/wp-includes/css/dist/format-library/style.min.css`)
addData("wp-list-reusable-blocks", "path", `/wp-includes/css/dist/list-reusable-blocks/style.min.css`)
addData("wp-reusable-blocks", "path", `/wp-includes/css/dist/reusable-blocks/style.min.css`)
addData("wp-nux", "path", `/wp-includes/css/dist/nux/style.min.css`)
addData("wp-widgets", "path", `/wp-includes/css/dist/widgets/style.min.css`)
addData("wp-edit-widgets", "path", `/wp-includes/css/dist/edit-widgets/style.min.css`)
addData("wp-customize-widgets", "path", `/wp-includes/css/dist/customize-widgets/style.min.css`)
addData("wp-edit-site", "path", `/wp-includes/css/dist/edit-site/style.min.css`)
addData("common", "rtl", `replace`)
addData("common", "suffix", `.min`)
addData("forms", "rtl", `replace`)
addData("forms", "suffix", `.min`)
addData("admin-menu", "rtl", `replace`)
addData("admin-menu", "suffix", `.min`)
addData("dashboard", "rtl", `replace`)
addData("dashboard", "suffix", `.min`)
addData("list-tables", "rtl", `replace`)
addData("list-tables", "suffix", `.min`)
addData("edit", "rtl", `replace`)
addData("edit", "suffix", `.min`)
addData("revisions", "rtl", `replace`)
addData("revisions", "suffix", `.min`)
addData("media", "rtl", `replace`)
addData("media", "suffix", `.min`)
addData("themes", "rtl", `replace`)
addData("themes", "suffix", `.min`)
addData("about", "rtl", `replace`)
addData("about", "suffix", `.min`)
addData("nav-menus", "rtl", `replace`)
addData("nav-menus", "suffix", `.min`)
addData("widgets", "rtl", `replace`)
addData("widgets", "suffix", `.min`)
addData("site-icon", "rtl", `replace`)
addData("site-icon", "suffix", `.min`)
addData("l10n", "rtl", `replace`)
addData("l10n", "suffix", `.min`)
addData("install", "rtl", `replace`)
addData("install", "suffix", `.min`)
addData("wp-color-picker", "rtl", `replace`)
addData("wp-color-picker", "suffix", `.min`)
addData("customize-controls", "rtl", `replace`)
addData("customize-controls", "suffix", `.min`)
addData("customize-widgets", "rtl", `replace`)
addData("customize-widgets", "suffix", `.min`)
addData("customize-nav-menus", "rtl", `replace`)
addData("customize-nav-menus", "suffix", `.min`)
addData("customize-preview", "rtl", `replace`)
addData("customize-preview", "suffix", `.min`)
addData("login", "rtl", `replace`)
addData("login", "suffix", `.min`)
addData("site-health", "rtl", `replace`)
addData("site-health", "suffix", `.min`)
addData("buttons", "rtl", `replace`)
addData("buttons", "suffix", `.min`)
addData("admin-bar", "rtl", `replace`)
addData("admin-bar", "suffix", `.min`)
addData("wp-auth-check", "rtl", `replace`)
addData("wp-auth-check", "suffix", `.min`)
addData("editor-buttons", "rtl", `replace`)
addData("editor-buttons", "suffix", `.min`)
addData("media-views", "rtl", `replace`)
addData("media-views", "suffix", `.min`)
addData("wp-pointer", "rtl", `replace`)
addData("wp-pointer", "suffix", `.min`)
addData("wp-jquery-ui-dialog", "rtl", `replace`)
addData("wp-jquery-ui-dialog", "suffix", `.min`)
addData("wp-reset-editor-styles", "rtl", `replace`)
addData("wp-reset-editor-styles", "suffix", `.min`)
addData("wp-editor-classic-layout-styles", "rtl", `replace`)
addData("wp-editor-classic-layout-styles", "suffix", `.min`)
addData("wp-block-library-theme", "rtl", `replace`)
addData("wp-block-library-theme", "suffix", `.min`)
addData("wp-edit-blocks", "rtl", `replace`)
addData("wp-edit-blocks", "suffix", `.min`)
addData("wp-block-editor", "rtl", `replace`)
addData("wp-block-editor", "suffix", `.min`)
addData("wp-block-library", "rtl", `replace`)
addData("wp-block-library", "suffix", `.min`)
addData("wp-block-directory", "rtl", `replace`)
addData("wp-block-directory", "suffix", `.min`)
addData("wp-components", "rtl", `replace`)
addData("wp-components", "suffix", `.min`)
addData("wp-customize-widgets", "rtl", `replace`)
addData("wp-customize-widgets", "suffix", `.min`)
addData("wp-edit-post", "rtl", `replace`)
addData("wp-edit-post", "suffix", `.min`)
addData("wp-edit-site", "rtl", `replace`)
addData("wp-edit-site", "suffix", `.min`)
addData("wp-edit-widgets", "rtl", `replace`)
addData("wp-edit-widgets", "suffix", `.min`)
addData("wp-editor", "rtl", `replace`)
addData("wp-editor", "suffix", `.min`)
addData("wp-format-library", "rtl", `replace`)
addData("wp-format-library", "suffix", `.min`)
addData("wp-list-reusable-blocks", "rtl", `replace`)
addData("wp-list-reusable-blocks", "suffix", `.min`)
addData("wp-reusable-blocks", "rtl", `replace`)
addData("wp-reusable-blocks", "suffix", `.min`)
addData("wp-nux", "rtl", `replace`)
addData("wp-nux", "suffix", `.min`)
addData("wp-widgets", "rtl", `replace`)
addData("wp-widgets", "suffix", `.min`)
addData("deprecated-media", "rtl", `replace`)
addData("deprecated-media", "suffix", `.min`)
addData("farbtastic", "rtl", `replace`)
addData("farbtastic", "suffix", `.min`)
AddData("json2", "conditional", `lt IE 8`)
AddData("wp-embed-template-ie", "conditional", `lte IE 8`)
AddData("wp-block-library-theme", "path", `wp-includes/css/dist/block-library/theme.min.css`)
AddData("wp-block-editor", "path", `/wp-includes/css/dist/block-editor/style.min.css`)
AddData("wp-block-library", "path", `/wp-includes/css/dist/block-library/style.min.css`)
AddData("wp-block-directory", "path", `/wp-includes/css/dist/block-directory/style.min.css`)
AddData("wp-components", "path", `/wp-includes/css/dist/components/style.min.css`)
AddData("wp-edit-post", "path", `/wp-includes/css/dist/edit-post/style.min.css`)
AddData("wp-editor", "path", `/wp-includes/css/dist/editor/style.min.css`)
AddData("wp-format-library", "path", `/wp-includes/css/dist/format-library/style.min.css`)
AddData("wp-list-reusable-blocks", "path", `/wp-includes/css/dist/list-reusable-blocks/style.min.css`)
AddData("wp-reusable-blocks", "path", `/wp-includes/css/dist/reusable-blocks/style.min.css`)
AddData("wp-nux", "path", `/wp-includes/css/dist/nux/style.min.css`)
AddData("wp-widgets", "path", `/wp-includes/css/dist/widgets/style.min.css`)
AddData("wp-edit-widgets", "path", `/wp-includes/css/dist/edit-widgets/style.min.css`)
AddData("wp-customize-widgets", "path", `/wp-includes/css/dist/customize-widgets/style.min.css`)
AddData("wp-edit-site", "path", `/wp-includes/css/dist/edit-site/style.min.css`)
AddData("common", "rtl", `replace`)
AddData("common", "suffix", `.min`)
AddData("forms", "rtl", `replace`)
AddData("forms", "suffix", `.min`)
AddData("admin-menu", "rtl", `replace`)
AddData("admin-menu", "suffix", `.min`)
AddData("dashboard", "rtl", `replace`)
AddData("dashboard", "suffix", `.min`)
AddData("list-tables", "rtl", `replace`)
AddData("list-tables", "suffix", `.min`)
AddData("edit", "rtl", `replace`)
AddData("edit", "suffix", `.min`)
AddData("revisions", "rtl", `replace`)
AddData("revisions", "suffix", `.min`)
AddData("media", "rtl", `replace`)
AddData("media", "suffix", `.min`)
AddData("themes", "rtl", `replace`)
AddData("themes", "suffix", `.min`)
AddData("about", "rtl", `replace`)
AddData("about", "suffix", `.min`)
AddData("nav-menus", "rtl", `replace`)
AddData("nav-menus", "suffix", `.min`)
AddData("widgets", "rtl", `replace`)
AddData("widgets", "suffix", `.min`)
AddData("site-icon", "rtl", `replace`)
AddData("site-icon", "suffix", `.min`)
AddData("l10n", "rtl", `replace`)
AddData("l10n", "suffix", `.min`)
AddData("install", "rtl", `replace`)
AddData("install", "suffix", `.min`)
AddData("wp-color-picker", "rtl", `replace`)
AddData("wp-color-picker", "suffix", `.min`)
AddData("customize-controls", "rtl", `replace`)
AddData("customize-controls", "suffix", `.min`)
AddData("customize-widgets", "rtl", `replace`)
AddData("customize-widgets", "suffix", `.min`)
AddData("customize-nav-menus", "rtl", `replace`)
AddData("customize-nav-menus", "suffix", `.min`)
AddData("customize-preview", "rtl", `replace`)
AddData("customize-preview", "suffix", `.min`)
AddData("login", "rtl", `replace`)
AddData("login", "suffix", `.min`)
AddData("site-health", "rtl", `replace`)
AddData("site-health", "suffix", `.min`)
AddData("buttons", "rtl", `replace`)
AddData("buttons", "suffix", `.min`)
AddData("admin-bar", "rtl", `replace`)
AddData("admin-bar", "suffix", `.min`)
AddData("wp-auth-check", "rtl", `replace`)
AddData("wp-auth-check", "suffix", `.min`)
AddData("editor-buttons", "rtl", `replace`)
AddData("editor-buttons", "suffix", `.min`)
AddData("media-views", "rtl", `replace`)
AddData("media-views", "suffix", `.min`)
AddData("wp-pointer", "rtl", `replace`)
AddData("wp-pointer", "suffix", `.min`)
AddData("wp-jquery-ui-dialog", "rtl", `replace`)
AddData("wp-jquery-ui-dialog", "suffix", `.min`)
AddData("wp-reset-editor-styles", "rtl", `replace`)
AddData("wp-reset-editor-styles", "suffix", `.min`)
AddData("wp-editor-classic-layout-styles", "rtl", `replace`)
AddData("wp-editor-classic-layout-styles", "suffix", `.min`)
AddData("wp-block-library-theme", "rtl", `replace`)
AddData("wp-block-library-theme", "suffix", `.min`)
AddData("wp-edit-blocks", "rtl", `replace`)
AddData("wp-edit-blocks", "suffix", `.min`)
AddData("wp-block-editor", "rtl", `replace`)
AddData("wp-block-editor", "suffix", `.min`)
AddData("wp-block-library", "rtl", `replace`)
AddData("wp-block-library", "suffix", `.min`)
AddData("wp-block-directory", "rtl", `replace`)
AddData("wp-block-directory", "suffix", `.min`)
AddData("wp-components", "rtl", `replace`)
AddData("wp-components", "suffix", `.min`)
AddData("wp-customize-widgets", "rtl", `replace`)
AddData("wp-customize-widgets", "suffix", `.min`)
AddData("wp-edit-post", "rtl", `replace`)
AddData("wp-edit-post", "suffix", `.min`)
AddData("wp-edit-site", "rtl", `replace`)
AddData("wp-edit-site", "suffix", `.min`)
AddData("wp-edit-widgets", "rtl", `replace`)
AddData("wp-edit-widgets", "suffix", `.min`)
AddData("wp-editor", "rtl", `replace`)
AddData("wp-editor", "suffix", `.min`)
AddData("wp-format-library", "rtl", `replace`)
AddData("wp-format-library", "suffix", `.min`)
AddData("wp-list-reusable-blocks", "rtl", `replace`)
AddData("wp-list-reusable-blocks", "suffix", `.min`)
AddData("wp-reusable-blocks", "rtl", `replace`)
AddData("wp-reusable-blocks", "suffix", `.min`)
AddData("wp-nux", "rtl", `replace`)
AddData("wp-nux", "suffix", `.min`)
AddData("wp-widgets", "rtl", `replace`)
AddData("wp-widgets", "suffix", `.min`)
AddData("deprecated-media", "rtl", `replace`)
AddData("deprecated-media", "suffix", `.min`)
AddData("farbtastic", "rtl", `replace`)
AddData("farbtastic", "suffix", `.min`)
}
@ -495,7 +494,7 @@ func defaultAddInLineScript() {
}
func defaultAddInLineStyle() {
AddInlineStyle("global-styles", ``)
AddInlineStyle("global-styles", GetGlobalStyletSheet())
AddInlineStyle("global-styles", `.wp-block-navigation a:where(:not(.wp-element-button)){color: inherit;}`)
AddInlineStyle("global-styles", `:where(.wp-block-columns.is-layout-flex){gap: 2em;}`)
AddInlineStyle("global-styles", `.wp-block-pullquote{font-size: 1.5em;line-height: 1.6;}`)
@ -504,10 +503,18 @@ func defaultAddInLineStyle() {
var re = regexp.MustCompile(`(?is:\([A-Za-z0-9'.:\-/, ]+\))`)
var rea = regexp.MustCompile(`array\(array\(.*?\)\)`)
func themeJson() {
func InitDefaultScriptSetting() {
initThemeJson()
defaultLocalize()
defaultTranslate()
defaultAddData()
defaultAddInLineScript()
defaultAddInLineStyle()
}
func initThemeJson() {
blocksData := __blocksData()
//path := config.GetConfig().WpDir
path := "/var/www/html/wordpress"
path := config.GetConfig().WpDir
f, err := os.ReadFile(filepath.Join(path, "wp-includes/theme.json"))
if err != nil {
logs.Error(err, "can't open theme json", path)
@ -523,7 +530,7 @@ func themeJson() {
t := ThemeJson{blocksData, j}
setThemeJson(j)
setSpacingSizes(t)
GetStyletSheet(t, nil, nil, nil)
__themeJson.Store(t)
}
func setThemeJson(m map[string]any) {
@ -594,7 +601,8 @@ func __propertyMap(m map[string]any) {
}
func __blocksData() map[string]any {
path := "/var/www/html/wordpress"
path := config.GetConfig().WpDir
//path := "/var/www/html/wordpress"
b, err := os.ReadFile(filepath.Join(path, "wp-includes/blocks/blocks-json.php"))
if err != nil {
logs.Error(err, "can't open block json", path)

View File

@ -1,4 +1,4 @@
package wp
package scriptloader
import (
"testing"
@ -14,7 +14,7 @@ func Test_themeJson(t *testing.T) {
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
themeJson()
initThemeJson()
})
}
}

View File

@ -1,10 +1,11 @@
package wp
package scriptloader
import (
"encoding/json"
"fmt"
"github.com/dlclark/regexp2"
"github.com/fthvgb1/wp-go/app/cmd/reload"
"github.com/fthvgb1/wp-go/app/theme/wp"
"github.com/fthvgb1/wp-go/app/wpconfig"
"github.com/fthvgb1/wp-go/helper"
"github.com/fthvgb1/wp-go/helper/maps"
@ -14,6 +15,7 @@ import (
"github.com/fthvgb1/wp-go/safety"
"html"
"math"
"path/filepath"
"regexp"
"strconv"
"strings"
@ -46,9 +48,9 @@ func localize(handle, objectname string, l10n map[string]any) string {
}
func AddStaticLocalize(handle, objectname string, l10n map[string]any) {
addData(handle, "data", localize(handle, objectname, l10n))
AddData(handle, "data", localize(handle, objectname, l10n))
}
func AddDynamicLocalize(h *Handle, handle, objectname string, l10n map[string]any) {
func AddDynamicLocalize(h *wp.Handle, handle, objectname string, l10n map[string]any) {
AddDynamicData(h, handle, "data", localize(handle, objectname, l10n))
}
@ -59,7 +61,7 @@ func getData(handle, key string) string {
}
return strings.Join(h.Extra[key], "\n")
}
func GetData(h *Handle, handle, key string) string {
func GetData(h *wp.Handle, handle, key string) string {
hh, ok := scripts.Load(handle)
if !ok {
return ""
@ -69,7 +71,7 @@ func GetData(h *Handle, handle, key string) string {
return strings.Join(d, "\n")
}
func addData(handle, key, data string) {
func AddData(handle, key, data string) {
s, ok := scripts.Load(handle)
if !ok {
s = NewScript(handle, "", nil, "", nil)
@ -87,14 +89,14 @@ func AddInlineScript(handle, data, position string) {
if position != "after" {
position = "before"
}
addData(handle, position, data)
AddData(handle, position, data)
}
func AddInlineStyle(handle, data string) {
if handle == "" || data == "" {
return
}
addData(handle, "after", data)
AddData(handle, "after", data)
}
func InlineScripts(handle, position string, display bool) string {
@ -114,6 +116,69 @@ func AddScript(handle string, src string, deps []string, ver string, args any) {
scripts.Store(handle, script)
}
var scriptQueues = scriptQueue{}
type scriptQueue struct {
Register map[string]struct{}
Queue []string
Args map[string]string
queuedBeforeRegister map[string]string
}
func EnqueueStyle(handle, src string, deps []string, ver, media string) {
if media == "" {
media = "all"
}
h := strings.Split(handle, "?")
if src != "" {
AddScript(h[0], src, deps, ver, media)
}
enqueue(handle)
}
func EnqueueStyles(handle, src string, deps []string, ver, media string) {
if src != "" {
src = GetThemeFileUri(src)
}
EnqueueStyle(handle, src, deps, ver, media)
}
func EnqueueScript(handle, src string, deps []string, ver string, inFooter bool) {
h := strings.Split(handle, "?")
if src != "" {
AddScript(h[0], src, deps, ver, nil)
}
if inFooter {
AddData(h[0], "group", "1")
}
enqueue(handle)
}
func EnqueueScripts(handle, src string, deps []string, ver string, inFooter bool) {
if src != "" {
src = GetThemeFileUri(src)
}
EnqueueScript(handle, src, deps, ver, inFooter)
}
func enqueue(handle string) {
h := strings.Split(handle, "?")
if slice.IsContained(scriptQueues.Queue, h[0]) && maps.IsExists(scriptQueues.Register, h[0]) {
scriptQueues.Queue = append(scriptQueues.Queue, h[0])
} else if maps.IsExists(scriptQueues.Register, h[0]) {
scriptQueues.queuedBeforeRegister[h[0]] = ""
if len(h) > 1 {
scriptQueues.queuedBeforeRegister[h[0]] = h[1]
}
}
}
func GetStylesheetUri() string {
return GetThemeFileUri("/styles.css")
}
func GetThemeFileUri(file string) string {
return filepath.Join("/wp-content/themes", wpconfig.GetOption("template"), file)
}
type Script struct {
Handle string `json:"handle,omitempty"`
Src string `json:"src,omitempty"`
@ -129,7 +194,7 @@ func NewScript(handle string, src string, deps []string, ver string, args any) *
return &Script{Handle: handle, Src: src, Deps: deps, Ver: ver, Args: args}
}
func AddDynamicData(h *Handle, handle, key, data string) {
func AddDynamicData(h *wp.Handle, handle, key, data string) {
da := helper.GetContextVal(h.C, "__scriptDynamicData__", map[string]map[string][]string{})
m, ok := da[handle]
if !ok {
@ -139,7 +204,7 @@ func AddDynamicData(h *Handle, handle, key, data string) {
da[handle] = m
}
func GetDynamicData(h *Handle, handle, key string) string {
func GetDynamicData(h *wp.Handle, handle, key string) string {
da := helper.GetContextVal(h.C, "__scriptDynamicData__", map[string]map[string][]string{})
if len(da) < 1 {
return ""
@ -906,7 +971,7 @@ func wpGetTypographyFontSizeValue(preset map[string]string, m map[string]any) st
return size
}
var __themeJson *safety.Var[ThemeJson]
var __themeJson = reload.Vars(ThemeJson{})
func GetThemeJson() ThemeJson {
return __themeJson.Load()
@ -1116,7 +1181,9 @@ func getStyleNodes(t ThemeJson) []node {
return styleNodes
}
func GetStyletSheet(t ThemeJson, types, origins []string, options map[string]string) string {
func GetGlobalStyletSheet() string {
t := __themeJson.Load()
var types, origins []string
if types == nil && !wpconfig.HasThemeJson() {
types = []string{"variables", "presets", "base-layout-styles"}
} else if types == nil {