fix: prevent asset conflicts between React and Grid.js versions

Add coexistence checks to all enqueue methods to prevent loading
both React and Grid.js assets simultaneously.

Changes:
- ReactAdmin.php: Only enqueue React assets when ?react=1
- Init.php: Skip Grid.js when React active on admin pages
- Form.php, Coupon.php, Access.php: Restore classic assets when ?react=0
- Customer.php, Product.php, License.php: Add coexistence checks

Now the toggle between Classic and React versions works correctly.

Co-authored-by: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
dwindown
2026-04-18 17:02:14 +07:00
parent bd9cdac02e
commit e8fbfb14c1
74973 changed files with 6658406 additions and 71 deletions

92
node_modules/rtlcss/lib/config-loader.js generated vendored Normal file
View File

@@ -0,0 +1,92 @@
'use strict'
const fs = require('fs')
const path = require('path')
const findUp = require('find-up')
const stripJSONComments = require('strip-json-comments')
let config = {}
const configSources = ['package.json', '.rtlcssrc', '.rtlcss.json']
const environments = [
process.env.USERPROFILE,
process.env.HOMEPATH,
process.env.HOME
]
const readConfig = (configFilePath) => {
return JSON.parse(stripJSONComments(fs.readFileSync(configFilePath, 'utf-8').trim()))
}
module.exports.load = (configFilePath, cwd, overrides) => {
if (configFilePath) {
return override(readConfig(configFilePath), overrides)
}
const directory = cwd || process.cwd()
config = loadConfig(directory)
if (!config) {
for (const environment of environments) {
if (!environment) {
continue
}
config = loadConfig(environment)
if (config) {
break
}
}
}
if (config) {
override(config, overrides)
}
return config
}
function loadConfig (cwd) {
for (const source of configSources) {
let foundPath
try {
foundPath = findUp.sync(source, { cwd })
} catch (e) {
continue
}
if (foundPath) {
const configFilePath = path.normalize(foundPath)
try {
config = readConfig(configFilePath)
} catch (e) {
throw new Error(`${e} ${configFilePath}`)
}
if (source === 'package.json') {
config = config.rtlcssConfig
}
if (config) {
return config
}
}
}
}
function override (to, from) {
if (to && from) {
for (const p in from) {
if (Object.prototype.hasOwnProperty.call(from, p)) {
if (Object.prototype.hasOwnProperty.call(to, p) && typeof to[p] === 'object') {
override(to[p], from[p])
} else {
to[p] = from[p]
}
}
}
}
return to
}

103
node_modules/rtlcss/lib/config.js generated vendored Normal file
View File

@@ -0,0 +1,103 @@
'use strict'
let options
const config = {}
const corePlugin = require('./plugin.js')
function sort (arr) {
return arr.sort((a, b) => a.priority - b.priority)
}
function optionOrDefault (option, def) {
return option in options ? options[option] : def
}
function addKey (key, def) {
config[key] = optionOrDefault(key, def)
}
function main (opts, plugins, hooks) {
options = opts || {}
hooks = hooks || {}
addKey('autoRename', false)
addKey('autoRenameStrict', false)
addKey('blacklist', {})
addKey('clean', true)
addKey('greedy', false)
addKey('processUrls', false)
addKey('stringMap', [])
addKey('useCalc', false)
addKey('aliases', {})
addKey('processEnv', true)
// default strings map
if (Array.isArray(config.stringMap)) {
let hasLeftRight, hasLtrRtl
for (const map of config.stringMap) {
if (hasLeftRight && hasLtrRtl) {
break
} else if (map.name === 'left-right') {
hasLeftRight = true
} else if (map.name === 'ltr-rtl') {
hasLtrRtl = true
}
}
if (!hasLeftRight) {
config.stringMap.push({
name: 'left-right',
priority: 100,
exclusive: false,
search: ['left', 'Left', 'LEFT'],
replace: ['right', 'Right', 'RIGHT'],
options: { scope: '*', ignoreCase: false }
})
}
if (!hasLtrRtl) {
config.stringMap.push({
name: 'ltr-rtl',
priority: 100,
exclusive: false,
search: ['ltr', 'Ltr', 'LTR'],
replace: ['rtl', 'Rtl', 'RTL'],
options: { scope: '*', ignoreCase: false }
})
}
sort(config.stringMap)
}
// plugins
config.plugins = []
if (Array.isArray(plugins)) {
if (!plugins.some((plugin) => plugin.name === 'rtlcss')) {
config.plugins.push(corePlugin)
}
config.plugins = config.plugins.concat(plugins)
} else if (!plugins || plugins.name !== 'rtlcss') {
config.plugins.push(corePlugin)
}
sort(config.plugins)
// hooks
config.hooks = {
pre () {},
post () {}
}
if (typeof hooks.pre === 'function') {
config.hooks.pre = hooks.pre
}
if (typeof hooks.post === 'function') {
config.hooks.post = hooks.post
}
return config
}
module.exports.configure = main

46
node_modules/rtlcss/lib/directive-parser.js generated vendored Normal file
View File

@@ -0,0 +1,46 @@
'use strict'
module.exports = (comment) => {
let pos = 0
let value = comment.text
const match = value.match(/^\s*!?\s*rtl:/)
let meta
if (match) {
meta = {
source: comment,
name: '',
param: '',
begin: true,
end: true,
blacklist: false,
preserve: false
}
value = value.slice(match[0].length)
pos = value.indexOf(':')
if (pos > -1) {
meta.name = value.slice(0, pos)
// begin/end are always true, unless one of them actually exists.
meta.begin = meta.name !== 'end'
meta.end = meta.name !== 'begin'
if (meta.name === 'begin' || meta.name === 'end') {
value = value.slice(meta.name.length + 1)
pos = value.indexOf(':')
if (pos > -1) {
meta.name = value.slice(0, pos)
value = value.slice(pos)
meta.param = value.slice(1)
} else {
meta.name = value
}
} else {
meta.param = value.slice(pos + 1)
}
} else {
meta.name = value
}
}
return meta
}

543
node_modules/rtlcss/lib/plugin.js generated vendored Normal file
View File

@@ -0,0 +1,543 @@
'use strict'
const config = require('./config.js')
const util = require('./util.js')
module.exports = {
name: 'rtlcss',
priority: 100,
directives: {
control: {
ignore: {
expect: { atrule: true, comment: true, decl: true, rule: true },
endNode: null,
begin (node, metadata, context) {
// find the ending node in case of self closing directive
if (!this.endNode && metadata.begin && metadata.end) {
let n = node
while (n && n.nodes) {
n = n.nodes[n.nodes.length - 1]
}
this.endNode = n
}
let prevent = true
if (node.type === 'comment' && node.text.match(/^\s*!?\s*rtl:end:ignore/)) {
prevent = false
}
return prevent
},
end (node, metadata, context) {
// end if:
// 1. block directive and the node is comment
// 2. self closing directive and node is endNode
if ((metadata.begin !== metadata.end && node.type === 'comment') || (metadata.begin && metadata.end && node === this.endNode)) {
// clear ending node
this.endNode = null
return true
}
return false
}
},
rename: {
expect: { rule: true },
begin (node, metadata, context) {
node.selector = context.util.applyStringMap(node.selector, false)
return false
},
end (node, context) {
return true
}
},
raw: {
expect: { self: true },
begin (node, metadata, context) {
const nodes = context.postcss.parse(metadata.param, { from: node.source.input.from })
nodes.walk((node) => {
node[context.symbol] = true
})
node.parent.insertBefore(node, nodes)
return true
},
end (node, context) {
return true
}
},
remove: {
expect: { atrule: true, rule: true, decl: true },
begin (node, metadata, context) {
let prevent = false
switch (node.type) {
case 'atrule':
case 'rule':
case 'decl':
prevent = true
node.remove()
}
return prevent
},
end (node, metadata, context) {
return true
}
},
options: {
expect: { self: true },
stack: [],
begin (node, metadata, context) {
this.stack.push(util.extend({}, context.config))
let options
try {
options = JSON.parse(metadata.param)
} catch (e) {
throw node.error('Invalid options object', { details: e })
}
context.config = config.configure(options, context.config.plugins)
context.util = util.configure(context.config)
return true
},
end (node, metadata, context) {
const config = this.stack.pop()
if (config && !metadata.begin) {
context.config = config
context.util = util.configure(context.config)
}
return true
}
},
config: {
expect: { self: true },
stack: [],
begin (node, metadata, context) {
this.stack.push(util.extend({}, context.config))
let configuration
try {
configuration = eval(`(${metadata.param})`) // eslint-disable-line no-eval
} catch (e) {
throw node.error('Invalid config object', { details: e })
}
context.config = config.configure(configuration.options, configuration.plugins)
context.util = util.configure(context.config)
return true
},
end (node, metadata, context) {
const config = this.stack.pop()
if (config && !metadata.begin) {
context.config = config
context.util = util.configure(context.config)
}
return true
}
}
},
value: [
{
name: 'ignore',
action (decl, expr, context) {
return true
}
},
{
name: 'prepend',
action (decl, expr, context) {
let prefix = ''
const hasRawValue = decl.raws.value && decl.raws.value.raw
const raw = `${decl.raws.between.substr(1).trim()}${hasRawValue ? decl.raws.value.raw : decl.value}${decl.important ? decl.raws.important.substr(9).trim() : ''}`
raw.replace(expr, (m, v) => {
prefix += v
})
decl.value = hasRawValue
? (decl.raws.value.raw = prefix + decl.raws.value.raw)
: prefix + decl.value
return true
}
},
{
name: 'append',
action (decl, expr, context) {
let suffix = ''
const hasRawValue = decl.raws.value && decl.raws.value.raw
const raw = `${decl.raws.between.substr(1).trim()}${hasRawValue ? decl.raws.value.raw : decl.value}${decl.important ? decl.raws.important.substr(9).trim() : ''}`
raw.replace(expr, (m, v) => {
suffix = v + suffix
})
decl.value = hasRawValue ? (decl.raws.value.raw += suffix) : decl.value + suffix
return true
}
},
{
name: 'insert',
action (decl, expr, context) {
const hasRawValue = decl.raws.value && decl.raws.value.raw
const raw = `${decl.raws.between.substr(1).trim()}${hasRawValue ? decl.raws.value.raw : decl.value}${decl.important ? decl.raws.important.substr(9).trim() : ''}`
const result = raw.replace(expr, (match, value) => hasRawValue ? value + match : value)
decl.value = hasRawValue ? (decl.raws.value.raw = result) : result
return true
}
},
{
name: '',
action (decl, expr, context) {
const hasRawValue = decl.raws.value && decl.raws.value.raw
const raw = `${decl.raws.between.substr(1).trim()}${hasRawValue ? decl.raws.value.raw : ''}${decl.important ? decl.raws.important.substr(9).trim() : ''}`
raw.replace(expr, (match, value) => {
decl.value = hasRawValue
? (decl.raws.value.raw = value + match)
: value
})
return true
}
}
]
},
processors: [
{
name: 'variable',
expr: /^--/im,
action (prop, value) {
return { prop, value }
}
},
{
name: 'direction',
expr: /direction/im,
action (prop, value, context) {
return { prop, value: context.util.swapLtrRtl(value) }
}
},
{
name: 'left',
expr: /left/im,
action (prop, value, context) {
return { prop: prop.replace(this.expr, () => 'right'), value }
}
},
{
name: 'right',
expr: /right/im,
action (prop, value, context) {
return { prop: prop.replace(this.expr, () => 'left'), value }
}
},
{
name: 'four-value syntax',
expr: /^(margin|padding|border-(color|style|width))$/ig,
cache: null,
action (prop, value, context) {
if (this.cache === null) {
this.cache = {
match: /[^\s\uFFFD]+/g
}
}
const state = context.util.guardFunctions(value)
const result = state.value.match(this.cache.match)
if (result && result.length === 4 && (state.store.length > 0 || result[1] !== result[3])) {
let i = 0
state.value = state.value.replace(this.cache.match, () => result[(4 - i++) % 4])
}
return { prop, value: context.util.unguardFunctions(state) }
}
},
{
name: 'border radius',
expr: /border-radius/ig,
cache: null,
flip (value) {
const parts = value.match(this.cache.match)
let i
if (parts) {
switch (parts.length) {
case 2:
i = 1
if (parts[0] !== parts[1]) {
value = value.replace(this.cache.match, () => parts[i--])
}
break
case 3:
// preserve leading whitespace.
value = value.replace(this.cache.white, (m) => `${m + parts[1]} `)
break
case 4:
i = 0
if (parts[0] !== parts[1] || parts[2] !== parts[3]) {
value = value.replace(this.cache.match, () => parts[(5 - i++) % 4])
}
break
}
}
return value
},
action (prop, value, context) {
if (this.cache === null) {
this.cache = {
match: /[^\s\uFFFD]+/g,
slash: /[^/]+/g,
white: /(^\s*)/
}
}
const state = context.util.guardFunctions(value)
state.value = state.value.replace(this.cache.slash, (m) => this.flip(m))
return { prop, value: context.util.unguardFunctions(state) }
}
},
{
name: 'shadow',
expr: /shadow/ig,
cache: null,
action (prop, value, context) {
if (this.cache === null) {
this.cache = {
replace: /[^,]+/g
}
}
const colorSafe = context.util.guardHexColors(value)
const funcSafe = context.util.guardFunctions(colorSafe.value)
funcSafe.value = funcSafe.value.replace(this.cache.replace, (m) => context.util.negate(m))
colorSafe.value = context.util.unguardFunctions(funcSafe)
return { prop, value: context.util.unguardHexColors(colorSafe) }
}
},
{
name: 'transform and perspective origin',
expr: /(?:transform|perspective)-origin/ig,
cache: null,
flip (value, context) {
if (value === '0') {
value = '100%'
} else if (value.match(this.cache.percent)) {
value = context.util.complement(value)
} else if (value.match(this.cache.length)) {
value = context.util.flipLength(value)
}
return value
},
action (prop, value, context) {
if (this.cache === null) {
this.cache = {
match: context.util.regex(['calc', 'percent', 'length'], 'g'),
percent: context.util.regex(['calc', 'percent'], 'i'),
length: context.util.regex(['length'], 'gi'),
xKeyword: /(left|right)/i
}
}
if (value.match(this.cache.xKeyword)) {
value = context.util.swapLeftRight(value)
} else {
const state = context.util.guardFunctions(value)
const parts = state.value.match(this.cache.match)
if (parts && parts.length > 0) {
parts[0] = this.flip(parts[0], context)
state.value = state.value.replace(this.cache.match, () => parts.shift())
value = context.util.unguardFunctions(state)
}
}
return { prop, value }
}
},
{
name: 'transform',
expr: /^(?!text-).*?transform$/ig,
cache: null,
flip (value, process, context) {
let i = 0
return value.replace(this.cache.unit, (num) => process(++i, num))
},
flipMatrix (value, context) {
return this.flip(value, (i, num) => {
if (i === 2 || i === 3 || i === 5) {
return context.util.negate(num)
}
return num
}, context)
},
flipMatrix3D (value, context) {
return this.flip(value, (i, num) => {
if (i === 2 || i === 4 || i === 5 || i === 13) {
return context.util.negate(num)
}
return num
}, context)
},
flipRotate3D (value, context) {
return this.flip(value, (i, num) => {
if (i === 1 || i === 4) {
return context.util.negate(num)
}
return num
}, context)
},
action (prop, value, context) {
if (this.cache === null) {
this.cache = {
negatable: /((translate)(x|3d)?|rotate(z|y)?)$/ig,
unit: context.util.regex(['calc', 'number'], 'g'),
matrix: /matrix$/i,
matrix3D: /matrix3d$/i,
skewXY: /skew(x|y)?$/i,
rotate3D: /rotate3d$/i
}
}
const state = context.util.guardFunctions(value)
return {
prop,
value: context.util.unguardFunctions(state, (v, n) => {
if (n.length) {
if (n.match(this.cache.matrix3D)) {
v = this.flipMatrix3D(v, context)
} else if (n.match(this.cache.matrix)) {
v = this.flipMatrix(v, context)
} else if (n.match(this.cache.rotate3D)) {
v = this.flipRotate3D(v, context)
} else if (n.match(this.cache.skewXY)) {
v = context.util.negateAll(v)
} else if (n.match(this.cache.negatable)) {
v = context.util.negate(v)
}
}
return v
})
}
}
},
{
name: 'transition',
expr: /transition(-property)?$/i,
action (prop, value, context) {
return { prop, value: context.util.swapLeftRight(value) }
}
},
{
name: 'background',
expr: /(background|object)(-position(-x)?|-image)?$/i,
cache: null,
flip (value, context) {
const state = util.saveTokens(value, true)
const parts = state.value.match(this.cache.match)
if (parts && parts.length > 0) {
const keywords = (state.value.match(this.cache.position) || '').length
if (/* edge offsets */ parts.length >= 3 || /* keywords only */ keywords === 2) {
state.value = util.swapLeftRight(state.value)
} else {
parts[0] = parts[0] === '0'
? '100%'
: (parts[0].match(this.cache.percent)
? context.util.complement(parts[0])
: (parts[0].match(this.cache.length)
? context.util.flipLength(parts[0])
: context.util.swapLeftRight(parts[0])))
state.value = state.value.replace(this.cache.match, () => parts.shift())
}
}
return util.restoreTokens(state)
},
update (context, value, name) {
if (name.match(this.cache.gradient)) {
value = context.util.swapLeftRight(value)
if (value.match(this.cache.angle)) {
value = context.util.negate(value)
}
} else if ((context.config.processUrls === true || context.config.processUrls.decl === true) && name.match(this.cache.url)) {
value = context.util.applyStringMap(value, true)
}
return value
},
action (prop, value, context) {
if (this.cache === null) {
this.cache = {
match: context.util.regex(['position', 'percent', 'length', 'calc'], 'ig'),
percent: context.util.regex(['calc', 'percent'], 'i'),
position: context.util.regex(['position'], 'g'),
length: context.util.regex(['length'], 'gi'),
gradient: /gradient$/i,
angle: /\d+(deg|g?rad|turn)/i,
url: /^url/i
}
}
const colorSafe = context.util.guardHexColors(value)
const funcSafe = context.util.guardFunctions(colorSafe.value)
const parts = funcSafe.value.split(',')
const lprop = prop.toLowerCase()
if (lprop !== 'background-image') {
for (let x = 0; x < parts.length; x++) {
parts[x] = this.flip(parts[x], context)
}
}
funcSafe.value = parts.join(',')
colorSafe.value = context.util.unguardFunctions(funcSafe, this.update.bind(this, context))
return {
prop,
value: context.util.unguardHexColors(colorSafe)
}
}
},
{
name: 'keyword',
expr: /float|clear|text-align/i,
action (prop, value, context) {
return { prop, value: context.util.swapLeftRight(value) }
}
},
{
name: 'cursor',
expr: /cursor/i,
cache: null,
update (context, value, name) {
if ((context.config.processUrls === true || context.config.processUrls.decl === true) && name.match(this.cache.url)) {
value = context.util.applyStringMap(value, true)
}
return value
},
flip (value) {
return value.replace(this.cache.replace, (s, m) => {
return s.replace(m, m.replace(this.cache.e, '*')
.replace(this.cache.w, 'e')
.replace(this.cache.star, 'w'))
})
},
action (prop, value, context) {
if (this.cache === null) {
this.cache = {
replace: /\b(ne|nw|se|sw|nesw|nwse)-resize/ig,
url: /^url/i,
e: /e/i,
w: /w/i,
star: /\*/i
}
}
const state = context.util.guardFunctions(value)
state.value = state.value.split(',')
.map((part) => this.flip(part))
.join(',')
return {
prop,
value: context.util.unguardFunctions(state, this.update.bind(this, context))
}
}
}
]
}

235
node_modules/rtlcss/lib/rtlcss.js generated vendored Normal file
View File

@@ -0,0 +1,235 @@
/**
* RTLCSS https://github.com/MohammadYounes/rtlcss
* Framework for transforming Cascading Style Sheets (CSS) from Left-To-Right (LTR) to Right-To-Left (RTL).
* Copyright 2017 Mohammad Younes.
* Licensed under MIT <https://opensource.org/licenses/mit-license.php>
*/
'use strict'
const postcss = require('postcss')
const state = require('./state.js')
const config = require('./config.js')
const util = require('./util.js')
module.exports = (options, plugins, hooks) => {
const processed = Symbol('processed')
const configuration = config.configure(options, plugins, hooks)
const context = {
// provides access to postcss
postcss,
// provides access to the current configuration
config: configuration,
// provides access to utilities object
util: util.configure(configuration),
// processed symbol
symbol: processed
}
let flipped = 0
const toBeRenamed = {}
function shouldProcess (node, result) {
if (!node[processed]) {
let prevent = false
state.walk((current) => {
// check if current directive is expecting this node
if (!current.metadata.blacklist && current.directive.expect[node.type]) {
// perform action and prevent further processing if result equals true
if (current.directive.begin(node, current.metadata, context)) {
prevent = true
}
// if should end? end it.
if (current.metadata.end && current.directive.end(node, current.metadata, context)) {
state.pop(current)
}
}
})
node[processed] = true
return !prevent
}
return false
}
return {
postcssPlugin: 'rtlcss',
Once (root, { result }) {
context.config.hooks.pre(root, postcss)
shouldProcess(root, result)
},
Rule (node, { result }) {
if (shouldProcess(node, result)) {
// new rule, reset flipped decl count to zero
flipped = 0
}
},
AtRule (node, { result }) {
if (shouldProcess(node, result) &&
// @rules requires url flipping only
(context.config.processUrls === true || context.config.processUrls.atrule === true)
) {
const params = context.util.applyStringMap(node.params, true)
node.params = params
}
},
Comment (node, { result }) {
if (shouldProcess(node, result)) {
state.parse(node, result, (current) => {
let push = true
if (current.directive === null) {
current.preserve = !context.config.clean
context.util.each(context.config.plugins, (plugin) => {
const blacklist = context.config.blacklist[plugin.name]
if (blacklist && blacklist[current.metadata.name] === true) {
current.metadata.blacklist = true
if (current.metadata.end) {
push = false
}
if (current.metadata.begin) {
result.warn(`directive "${plugin.name}.${current.metadata.name}" is blacklisted.`, { node: current.source })
}
// break each
return false
}
current.directive = plugin.directives.control[current.metadata.name]
if (current.directive) {
// break each
return false
}
})
}
if (current.directive) {
if (!current.metadata.begin && current.metadata.end) {
if (current.directive.end(node, current.metadata, context)) {
state.pop(current)
}
push = false
} else if (
current.directive.expect.self && current.directive.begin(node, current.metadata, context) &&
current.metadata.end && current.directive.end(node, current.metadata, context)
) {
push = false
}
} else if (!current.metadata.blacklist) {
push = false
result.warn(`unsupported directive "${current.metadata.name}".`, { node: current.source })
}
return push
})
}
},
Declaration (node, { result }) {
if (shouldProcess(node, result)) {
// if broken by a matching value directive .. break
if (!context.util.each(context.config.plugins, (plugin) => {
return context.util.each(plugin.directives.value, (directive) => {
const hasRawValue = node.raws.value && node.raws.value.raw
const expr = context.util.regexDirective(directive.name)
if (expr.test(`${node.raws.between}${hasRawValue ? node.raws.value.raw : ''}${node.important && node.raws.important ? node.raws.important : ''}`)) {
expr.lastIndex = 0
if (directive.action(node, expr, context)) {
if (context.config.clean) {
node.raws.between = context.util.trimDirective(node.raws.between)
if (node.important && node.raws.important) {
node.raws.important = context.util.trimDirective(node.raws.important)
}
if (hasRawValue) {
node.value = node.raws.value.raw = context.util.trimDirective(node.raws.value.raw)
}
}
flipped++
// break
return false
}
}
})
})) return
// loop over all plugins/property processors
context.util.each(context.config.plugins, (plugin) => {
return context.util.each(plugin.processors, (processor) => {
const alias = context.config.aliases[node.prop]
if ((alias || node.prop).match(processor.expr)) {
const raw = node.raws.value && node.raws.value.raw ? node.raws.value.raw : node.value
const state = context.util.saveComments(raw)
if (context.config.processEnv) {
state.value = context.util.swap(state.value, 'safe-area-inset-left', 'safe-area-inset-right', { ignoreCase: false })
}
const pair = processor.action(node.prop, state.value, context)
state.value = pair.value
pair.value = context.util.restoreComments(state)
if ((!alias && pair.prop !== node.prop) || pair.value !== raw) {
flipped++
node.prop = pair.prop
node.value = pair.value
}
// match found, break
return false
}
})
})
// if last decl, apply auto rename
// decl. may be found inside @rules
if (context.config.autoRename && !flipped && node.parent.type === 'rule' && context.util.isLastOfType(node)) {
const renamed = context.util.applyStringMap(node.parent.selector)
if (context.config.autoRenameStrict === true) {
const pair = toBeRenamed[renamed]
if (pair) {
pair.selector = node.parent.selector
node.parent.selector = renamed
} else {
toBeRenamed[node.parent.selector] = node.parent
}
} else {
node.parent.selector = renamed
}
}
}
},
OnceExit (root, { result }) {
state.walk((item) => {
result.warn(`unclosed directive "${item.metadata.name}".`, { node: item.source })
})
for (const key of Object.keys(toBeRenamed)) {
result.warn('renaming skipped due to lack of a matching pair.', { node: toBeRenamed[key] })
}
context.config.hooks.post(root, postcss)
}
}
}
module.exports.postcss = true
/**
* Creates a new RTLCSS instance, process the input and return its result.
* @param {String} css A string containing input CSS.
* @param {Object} options An object containing RTLCSS settings.
* @param {Object|Array} plugins An array containing a list of RTLCSS plugins or a single RTLCSS plugin.
* @param {Object} hooks An object containing pre/post hooks.
* @returns {String} A string contining the RTLed css.
*/
module.exports.process = function (css, options, plugins, hooks) {
return postcss([this(options, plugins, hooks)]).process(css).css
}
/**
* Creates a new instance of RTLCSS using the passed configuration object
* @param {Object} config An object containing RTLCSS options, plugins and hooks.
* @returns {Object} A new RTLCSS instance.
*/
module.exports.configure = function (config) {
config = config || {}
return postcss([this(config.options, config.plugins, config.hooks)])
}

50
node_modules/rtlcss/lib/state.js generated vendored Normal file
View File

@@ -0,0 +1,50 @@
'use strict'
const directiveParser = require('./directive-parser.js')
module.exports = {
stack: [],
pop (current) {
const index = this.stack.indexOf(current)
if (index !== -1) {
this.stack.splice(index, 1)
}
if (!current.preserve) {
current.source.remove()
}
},
parse (node, lazyResult, callback) {
let current
const metadata = directiveParser(node)
if (metadata) {
if (!metadata.begin && metadata.end) {
this.walk((item) => {
if (metadata.name === item.metadata.name) {
this.pop(item)
current = { metadata, directive: item.directive, source: node, preserve: item.preserve }
return false
}
})
} else {
current = { metadata, directive: null, source: node, preserve: null }
}
if (current === undefined) {
lazyResult.warn(`found end "${metadata.name}" without a matching begin.`, { node: node })
} else if (callback(current)) {
this.stack.push(current)
} else if (!current.preserve) {
current.source.remove()
}
}
},
walk (callback) {
let len = this.stack.length
while (--len > -1) {
if (!callback(this.stack[len])) {
break
}
}
}
}

289
node_modules/rtlcss/lib/util.js generated vendored Normal file
View File

@@ -0,0 +1,289 @@
'use strict'
let config
let tokenId = 0
const CHAR_COMMENT_REPLACEMENT = '\uFFFD' // <20>
const CHAR_TOKEN_REPLACEMENT = '\u00A4' // ¤
const CHAR_TOKEN_START = '\u00AB' // «
const CHAR_TOKEN_END = '\u00BB' // »
const REGEX_COMMENT_REPLACEMENT = new RegExp(CHAR_COMMENT_REPLACEMENT, 'ig')
const REGEX_TOKEN_REPLACEMENT = new RegExp(CHAR_TOKEN_REPLACEMENT, 'ig')
const PATTERN_NUMBER = '\\-?(\\d*?\\.\\d+|\\d+)'
const PATTERN_NUMBER_WITH_CALC = '(calc' + CHAR_TOKEN_REPLACEMENT + ')|(' + PATTERN_NUMBER + ')(?!d\\()'
const PATTERN_TOKEN = CHAR_TOKEN_START + '\\d+:\\d+' + CHAR_TOKEN_END // «offset:index»
const PATTERN_TOKEN_WITH_NAME = '\\w*?' + CHAR_TOKEN_START + '\\d+:\\d+' + CHAR_TOKEN_END // «offset:index»
const REGEX_COMMENT = /\/\*[^]*?\*\//igm // non-greedy
const REGEX_DIRECTIVE = /\/\*\s*(?:!)?\s*rtl:[^]*?\*\//img
const REGEX_ESCAPE = /[.*+?^${}()|[\]\\]/g
const REGEX_FUNCTION = /\([^()]+\)/i
const REGEX_HEX_COLOR = /#[a-f0-9]{3,6}/ig
const REGEX_CALC = /calc/
const REGEX_TOKENS = new RegExp(PATTERN_TOKEN, 'ig')
const REGEX_TOKENS_WITH_NAME = new RegExp(PATTERN_TOKEN_WITH_NAME, 'ig')
const REGEX_COMPLEMENT = new RegExp(PATTERN_NUMBER_WITH_CALC, 'i')
const REGEX_NEGATE_ALL = new RegExp(PATTERN_NUMBER_WITH_CALC, 'ig')
const REGEX_NEGATE_ONE = new RegExp(PATTERN_NUMBER_WITH_CALC, 'i')
const DEFAULT_STRING_MAP_OPTIONS = { scope: '*', ignoreCase: true }
function compare (what, to, ignoreCase) {
return ignoreCase
? what.toLowerCase() === to.toLowerCase()
: what === to
}
function escapeRegExp (string) {
return string.replace(REGEX_ESCAPE, '\\$&')
}
module.exports = {
extend (dest, src) {
if (typeof dest === 'undefined' || typeof dest !== 'object') {
dest = {}
}
for (const prop in src) {
if (!Object.prototype.hasOwnProperty.call(dest, prop)) {
dest[prop] = src[prop]
}
}
return dest
},
swap (value, a, b, options) {
let expr = `${escapeRegExp(a)}|${escapeRegExp(b)}`
options = options || DEFAULT_STRING_MAP_OPTIONS
const greedy = Object.prototype.hasOwnProperty.call(options, 'greedy') ? options.greedy : config.greedy
if (!greedy) expr = `\\b(${expr})\\b`
const flags = options.ignoreCase ? 'img' : 'mg'
return value.replace(new RegExp(expr, flags), (m) => compare(m, a, options.ignoreCase) ? b : a)
},
swapLeftRight (value) {
return this.swap(value, 'left', 'right')
},
swapLtrRtl (value) {
return this.swap(value, 'ltr', 'rtl')
},
applyStringMap (value, isUrl) {
let result = value
for (const map of config.stringMap) {
const options = this.extend(map.options, DEFAULT_STRING_MAP_OPTIONS)
if (options.scope === '*' || (isUrl && options.scope === 'url') || (!isUrl && options.scope === 'selector')) {
if (Array.isArray(map.search) && Array.isArray(map.replace)) {
for (let mapIndex = 0; mapIndex < map.search.length; mapIndex++) {
result = this.swap(result, map.search[mapIndex], map.replace[mapIndex % map.search.length], options)
}
} else {
result = this.swap(result, map.search, map.replace, options)
}
if (map.exclusive === true) {
break
}
}
}
return result
},
negate (value) {
const state = this.saveTokens(value)
state.value = state.value.replace(REGEX_NEGATE_ONE, (num) => {
return REGEX_TOKEN_REPLACEMENT.test(num)
? num.replace(REGEX_TOKEN_REPLACEMENT, (m) => '(-1*' + m + ')')
: Number.parseFloat(num) * -1
})
return this.restoreTokens(state)
},
negateAll (value) {
const state = this.saveTokens(value)
state.value = state.value.replace(REGEX_NEGATE_ALL, (num) => {
return REGEX_TOKEN_REPLACEMENT.test(num)
? num.replace(REGEX_TOKEN_REPLACEMENT, (m) => '(-1*' + m + ')')
: Number.parseFloat(num) * -1
})
return this.restoreTokens(state)
},
complement (value) {
const state = this.saveTokens(value)
state.value = state.value.replace(REGEX_COMPLEMENT, (num) => {
return REGEX_TOKEN_REPLACEMENT.test(num)
? num.replace(REGEX_TOKEN_REPLACEMENT, (m) => '(100% - ' + m + ')')
: 100 - Number.parseFloat(num)
})
return this.restoreTokens(state)
},
flipLength (value) {
return config.useCalc ? `calc(100% - ${value})` : value
},
save (what, who, replacement, restorer, exclude) {
const state = {
value: who,
store: [],
replacement,
restorer
}
state.value = state.value.replace(what, (c) => {
if (exclude && c.match(exclude)) {
return c
}
state.store.push(c)
return state.replacement
})
return state
},
restore (state) {
let index = 0
const result = state.value.replace(state.restorer, () => {
return state.store[index++]
})
state.store.length = 0
return result
},
saveComments (value) {
return this.save(REGEX_COMMENT, value, CHAR_COMMENT_REPLACEMENT, REGEX_COMMENT_REPLACEMENT)
},
restoreComments (state) {
return this.restore(state)
},
saveTokens (value, excludeCalc) {
return excludeCalc === true
? this.save(REGEX_TOKENS_WITH_NAME, value, CHAR_TOKEN_REPLACEMENT, REGEX_TOKEN_REPLACEMENT, REGEX_CALC)
: this.save(REGEX_TOKENS, value, CHAR_TOKEN_REPLACEMENT, REGEX_TOKEN_REPLACEMENT)
},
restoreTokens (state) {
return this.restore(state)
},
guard (what, who, indexed) {
const state = {
value: who,
store: [],
offset: tokenId++,
token: CHAR_TOKEN_START + tokenId,
indexed: indexed === true
}
if (state.indexed === true) {
while (what.test(state.value)) {
state.value = state.value.replace(what, (m) => {
state.store.push(m)
return `${state.token}:${state.store.length}${CHAR_TOKEN_END}`
})
}
} else {
state.value = state.value.replace(what, (m) => {
state.store.push(m)
return state.token + CHAR_TOKEN_END
})
}
return state
},
unguard (state, callback) {
if (state.indexed === true) {
const detokenizer = new RegExp('(\\w*?)' + state.token + ':(\\d+)' + CHAR_TOKEN_END, 'i')
while (detokenizer.test(state.value)) {
state.value = state.value.replace(detokenizer, (match, name, index) => {
const value = state.store[index - 1]
return typeof callback === 'function'
? name + callback(value, name)
: name + value
})
}
return state.value
}
return state.value.replace(new RegExp('(\\w*?)' + state.token + CHAR_TOKEN_END, 'i'), (match, name) => {
const value = state.store.shift()
return typeof callback === 'function'
? name + callback(value, name)
: name + value
})
},
guardHexColors (value) {
return this.guard(REGEX_HEX_COLOR, value, true)
},
unguardHexColors (state, callback) {
return this.unguard(state, callback)
},
guardFunctions (value) {
return this.guard(REGEX_FUNCTION, value, true)
},
unguardFunctions (state, callback) {
return this.unguard(state, callback)
},
trimDirective (value) {
return value.replace(REGEX_DIRECTIVE, '')
},
regexCache: {},
regexDirective (name) {
// /(?:\/\*(?:!)?rtl:ignore(?::)?)([^]*?)(?:\*\/)/img
this.regexCache[name] = this.regexCache[name] || new RegExp('(?:\\/\\*\\s*(?:!)?\\s*rtl:' + (name ? escapeRegExp(name) + '(?::)?' : '') + ')([^]*?)(?:\\*\\/)', 'img')
return this.regexCache[name]
},
regex (what, options) {
what = what || []
let expression = ''
for (const exp of what) {
switch (exp) {
case 'percent':
expression += `|(${PATTERN_NUMBER}%)`
break
case 'length':
expression += `|(${PATTERN_NUMBER})(?:ex|ch|r?em|vh|vw|vmin|vmax|px|mm|cm|in|pt|pc)?`
break
case 'number':
expression += `|(${PATTERN_NUMBER})`
break
case 'position':
expression += '|(left|center|right|top|bottom)'
break
case 'calc':
expression += `|(calc${PATTERN_TOKEN})`
break
}
}
return new RegExp(expression.slice(1), options)
},
isLastOfType (node) {
let isLast = true
let next = node.next()
while (next) {
if (next.type === node.type) {
isLast = false
break
}
next = next.next()
}
return isLast
},
/**
* Simple breakable each: returning false in the callback will break the loop
* returns false if the loop was broken, otherwise true
*/
each (array, callback) {
for (const element of array) {
if (callback(element) === false) {
return false
}
}
return true
}
}
module.exports.configure = function (configuration) {
config = configuration
return this
}