package resolver

import (
	
	
	
	
)

type DataURL struct {
	mimeType string
	data     string
	isBase64 bool
}

func ( string) ( DataURL,  bool) {
	if strings.HasPrefix(, "data:") {
		if  := strings.IndexByte(, ',');  != -1 {
			.mimeType = [len("data:"):]
			.data = [+1:]
			if strings.HasSuffix(.mimeType, ";base64") {
				.mimeType = .mimeType[:len(.mimeType)-len(";base64")]
				.isBase64 = true
			}
			 = true
		}
	}
	return
}

type MIMEType uint8

const (
	MIMETypeUnsupported MIMEType = iota
	MIMETypeTextCSS
	MIMETypeTextJavaScript
	MIMETypeApplicationJSON
)

Remove things like ";charset=utf-8"
	 := .mimeType
	if  := strings.IndexByte(, ';');  != -1 {
		 = [:]
	}
Hard-code a few supported types
	switch  {
	case "text/css":
		return MIMETypeTextCSS
	case "text/javascript":
		return MIMETypeTextJavaScript
	case "application/json":
		return MIMETypeApplicationJSON
	default:
		return MIMETypeUnsupported
	}
}

Try to read base64 data
	if .isBase64 {
		,  := base64.StdEncoding.DecodeString(.data)
		if  != nil {
			return "", fmt.Errorf("Could not decode base64 data: %s", .Error())
		}
		return string(), nil
	}
Try to read percent-escaped data
	,  := url.PathUnescape(.data)
	if  != nil {
		return "", fmt.Errorf("Could not decode percent-escaped data: %s", .Error())
	}
	return , nil